@firecms/core 3.0.0-rc.4 → 3.0.0-tw4.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/components/VirtualTable/VirtualTable.performance.test.d.ts +1 -0
- package/dist/hooks/useProjectLog.d.ts +1 -1
- package/dist/index.es.js +39 -22
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +39 -22
- package/dist/index.umd.js.map +1 -1
- package/dist/util/entity_cache.d.ts +0 -1
- package/dist/util/strings.d.ts +1 -0
- package/dist/util/strings.test.d.ts +1 -0
- package/package.json +15 -14
- package/src/app/Scaffold.tsx +1 -1
- package/src/components/ArrayContainer.tsx +1 -1
- package/src/components/EntityCollectionTable/EntityCollectionRowActions.tsx +1 -1
- package/src/components/EntityCollectionTable/internal/EntityTableCell.tsx +3 -3
- package/src/components/ReferenceWidget.tsx +1 -1
- package/src/components/SelectableTable/SelectableTable.tsx +1 -1
- package/src/components/VirtualTable/VirtualTable.performance.test.tsx +386 -0
- package/src/components/VirtualTable/VirtualTable.tsx +3 -3
- package/src/components/VirtualTable/VirtualTableHeader.tsx +1 -1
- package/src/components/VirtualTable/VirtualTableRow.tsx +1 -1
- package/src/core/DefaultDrawer.tsx +1 -1
- package/src/core/DrawerNavigationItem.tsx +4 -3
- package/src/core/SideDialogs.tsx +19 -8
- package/src/hooks/useProjectLog.tsx +1 -1
- package/src/preview/components/EmptyValue.tsx +1 -1
- package/src/util/entity_cache.ts +0 -5
- package/src/util/strings.test.ts +101 -0
- package/src/util/strings.ts +21 -0
|
@@ -12,7 +12,6 @@ export declare function hasEntityInCache(path: string): boolean;
|
|
|
12
12
|
* Retrieves an entity from the in-memory cache or `localStorage`.
|
|
13
13
|
* If the entity is not in the cache but exists in `localStorage`, it loads it into the cache.
|
|
14
14
|
* @param path - The unique path/key for the entity.
|
|
15
|
-
* @param useLocalStorage
|
|
16
15
|
* @returns The cached entity or `undefined` if not found.
|
|
17
16
|
*/
|
|
18
17
|
export declare function getEntityFromCache(path: string): object | undefined;
|
package/dist/util/strings.d.ts
CHANGED
|
@@ -4,3 +4,4 @@ export declare function randomString(strLength?: number): string;
|
|
|
4
4
|
export declare function randomColor(): string;
|
|
5
5
|
export declare function slugify(text?: string, separator?: string, lowercase?: boolean): string;
|
|
6
6
|
export declare function unslugify(slug?: string): string;
|
|
7
|
+
export declare function prettifyIdentifier(input: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firecms/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.0.0-
|
|
4
|
+
"version": "3.0.0-tw4.13",
|
|
5
5
|
"description": "Awesome Firebase/Firestore-based headless open-source CMS",
|
|
6
6
|
"funding": {
|
|
7
7
|
"url": "https://github.com/sponsors/firecmsco"
|
|
@@ -53,10 +53,10 @@
|
|
|
53
53
|
"@dnd-kit/core": "^6.3.1",
|
|
54
54
|
"@dnd-kit/modifiers": "^9.0.0",
|
|
55
55
|
"@dnd-kit/sortable": "^10.0.0",
|
|
56
|
-
"@firecms/editor": "^3.0.0-
|
|
57
|
-
"@firecms/formex": "^3.0.0-
|
|
58
|
-
"@firecms/ui": "^3.0.0-
|
|
59
|
-
"@radix-ui/react-portal": "^1.1.
|
|
56
|
+
"@firecms/editor": "^3.0.0-tw4.13",
|
|
57
|
+
"@firecms/formex": "^3.0.0-tw4.13",
|
|
58
|
+
"@firecms/ui": "^3.0.0-tw4.13",
|
|
59
|
+
"@radix-ui/react-portal": "^1.1.10",
|
|
60
60
|
"clsx": "^2.1.1",
|
|
61
61
|
"compressorjs": "^1.2.1",
|
|
62
62
|
"date-fns": "^3.6.0",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"react-transition-group": "^4.4.5",
|
|
72
72
|
"react-use-measure": "^2.1.7",
|
|
73
73
|
"react-window": "^1.8.11",
|
|
74
|
-
"vite-plugin-static-copy": "3.1.
|
|
74
|
+
"vite-plugin-static-copy": "3.1.4",
|
|
75
75
|
"yup": "^0.32.11"
|
|
76
76
|
},
|
|
77
77
|
"peerDependencies": {
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"react-router-dom": "^6.28.0"
|
|
82
82
|
},
|
|
83
83
|
"devDependencies": {
|
|
84
|
-
"@jest/globals": "^30.
|
|
84
|
+
"@jest/globals": "^30.2.0",
|
|
85
85
|
"@testing-library/react": "^16.3.0",
|
|
86
86
|
"@testing-library/user-event": "^14.6.1",
|
|
87
87
|
"@types/jest": "^29.5.14",
|
|
@@ -93,22 +93,23 @@
|
|
|
93
93
|
"@vitejs/plugin-react": "^4.7.0",
|
|
94
94
|
"babel-plugin-react-compiler": "^19.0.0-beta-af1b7da-20250417",
|
|
95
95
|
"cross-env": "^7.0.3",
|
|
96
|
-
"eslint-plugin-react-compiler": "^19.
|
|
96
|
+
"eslint-plugin-react-compiler": "^19.1.0-rc.2",
|
|
97
97
|
"jest": "^29.7.0",
|
|
98
|
+
"jest-environment-jsdom": "^30.2.0",
|
|
98
99
|
"npm-run-all": "^4.1.5",
|
|
99
|
-
"react-router": "^6.30.
|
|
100
|
-
"react-router-dom": "^6.30.
|
|
101
|
-
"ts-jest": "^29.4.
|
|
100
|
+
"react-router": "^6.30.2",
|
|
101
|
+
"react-router-dom": "^6.30.2",
|
|
102
|
+
"ts-jest": "^29.4.5",
|
|
102
103
|
"ts-node": "^10.9.2",
|
|
103
104
|
"tsd": "^0.31.2",
|
|
104
|
-
"typescript": "^5.9.
|
|
105
|
-
"vite": "^7.
|
|
105
|
+
"typescript": "^5.9.3",
|
|
106
|
+
"vite": "^7.2.4"
|
|
106
107
|
},
|
|
107
108
|
"files": [
|
|
108
109
|
"dist",
|
|
109
110
|
"src"
|
|
110
111
|
],
|
|
111
|
-
"gitHead": "
|
|
112
|
+
"gitHead": "eca601fe784ee2a697eb0ef0a9b4a4fedd13a1e9",
|
|
112
113
|
"publishConfig": {
|
|
113
114
|
"access": "public"
|
|
114
115
|
},
|
package/src/app/Scaffold.tsx
CHANGED
|
@@ -228,7 +228,7 @@ function DrawerWrapper(props: {
|
|
|
228
228
|
open={props.open}
|
|
229
229
|
onOpenChange={props.setDrawerOpen}
|
|
230
230
|
title={"Navigation drawer"}
|
|
231
|
-
overlayClassName={"bg-white bg-opacity-80"}
|
|
231
|
+
overlayClassName={"bg-white bg-opacity-80 bg-white/80"}
|
|
232
232
|
>
|
|
233
233
|
{innerDrawer}
|
|
234
234
|
</Sheet>
|
|
@@ -186,7 +186,7 @@ export function ArrayContainerItem({
|
|
|
186
186
|
<div
|
|
187
187
|
ref={nodeRef}
|
|
188
188
|
style={style}
|
|
189
|
-
className={`relative ${!isDragging ? "hover\\:bg-surface-accent-50 dark\\:hover\\:bg-surface-800 dark\\:hover\\:bg-opacity-20" : ""} rounded-md opacity-100`}
|
|
189
|
+
className={`relative ${!isDragging ? "hover\\:bg-surface-accent-50 dark\\:hover\\:bg-surface-800 dark\\:hover\\:bg-opacity-20 dark\\:hover\\:bg-surface-800/20" : ""} rounded-md opacity-100`}
|
|
190
190
|
>
|
|
191
191
|
<div className="flex items-start">
|
|
192
192
|
<div className="flex-grow w-[calc(100%-48px)] text-text-primary dark:text-text-primary-dark">
|
|
@@ -75,7 +75,7 @@ export const EntityCollectionRowActions = function EntityCollectionRowActions({
|
|
|
75
75
|
return (
|
|
76
76
|
<div
|
|
77
77
|
className={cls(
|
|
78
|
-
"h-full flex items-center justify-center flex-col bg-surface-50 dark:bg-surface-900 bg-opacity-90 dark:bg-opacity-90 z-10",
|
|
78
|
+
"h-full flex items-center justify-center flex-col bg-surface-50 dark:bg-surface-900 bg-opacity-90 bg-surface-50/90 dark:bg-opacity-90 dark:bg-surface-900/90 z-10",
|
|
79
79
|
frozen ? "sticky left-0" : ""
|
|
80
80
|
)}
|
|
81
81
|
onClick={useCallback((event: any) => {
|
|
@@ -188,9 +188,9 @@ export const EntityTableCell = React.memo<EntityTableCellProps>(
|
|
|
188
188
|
<div
|
|
189
189
|
className={cls(
|
|
190
190
|
"transition-colors duration-100 ease-in-out",
|
|
191
|
-
`flex relative h-full rounded-md p-${p} border border-4
|
|
191
|
+
`flex relative h-full rounded-md p-${p} border border-4 border-opacity-75`,
|
|
192
192
|
onHover && !disabled ? "bg-surface-50 dark:bg-surface-900" : "",
|
|
193
|
-
saved ? "bg-surface-100
|
|
193
|
+
saved ? "bg-surface-100/75 dark:bg-surface-800/75" : "",
|
|
194
194
|
hideOverflow ? "overflow-hidden" : "",
|
|
195
195
|
isSelected ? "bg-surface-50 dark:bg-surface-900" : "",
|
|
196
196
|
borderClass
|
|
@@ -237,7 +237,7 @@ export const EntityTableCell = React.memo<EntityTableCellProps>(
|
|
|
237
237
|
{disabled && onHover && disabledTooltip &&
|
|
238
238
|
<div className="absolute top-1 right-1 text-xs">
|
|
239
239
|
<Tooltip title={disabledTooltip}>
|
|
240
|
-
<DoNotDisturbOnIcon size={"smallest"} color={"disabled"} className={"text-
|
|
240
|
+
<DoNotDisturbOnIcon size={"smallest"} color={"disabled"} className={"text-text-disabled"}/>
|
|
241
241
|
</Tooltip>
|
|
242
242
|
</div>}
|
|
243
243
|
|
|
@@ -136,7 +136,7 @@ export function ReferenceWidget<M extends Record<string, any>>({
|
|
|
136
136
|
"min-w-80 flex flex-col gap-4",
|
|
137
137
|
"relative transition-colors duration-200 ease-in rounded font-medium",
|
|
138
138
|
disabled ? "bg-opacity-50" : "hover:bg-opacity-75",
|
|
139
|
-
"text-opacity-50 dark:text-white dark:text-opacity-50",
|
|
139
|
+
"text-opacity-50 text-text-primary/50 dark:text-white dark:text-opacity-50 dark:text-white/50",
|
|
140
140
|
className
|
|
141
141
|
)}
|
|
142
142
|
>
|
|
@@ -247,7 +247,7 @@ export const SelectableTable = function SelectableTable<M extends Record<string,
|
|
|
247
247
|
checkFilterCombination={checkFilterCombination}
|
|
248
248
|
createFilterField={filterable ? createFilterField : undefined}
|
|
249
249
|
rowClassName={useCallback((entity: Entity<M>) => {
|
|
250
|
-
return highlightedRow?.(entity) ? "bg-surface-100 bg-opacity-75 dark:bg-surface-800 dark:bg-opacity-75" : "";
|
|
250
|
+
return highlightedRow?.(entity) ? "bg-surface-100 bg-opacity-75 bg-surface-100/75 dark:bg-surface-800 dark:bg-opacity-75 dark:bg-surface-800/75" : "";
|
|
251
251
|
}, [highlightedRow])}
|
|
252
252
|
className="flex-grow"
|
|
253
253
|
emptyComponent={emptyComponent}
|
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @jest-environment jsdom
|
|
4
|
+
*/
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { render, act } from '@testing-library/react';
|
|
7
|
+
import { VirtualTable } from './VirtualTable';
|
|
8
|
+
import { VirtualTableProps } from './VirtualTableProps';
|
|
9
|
+
|
|
10
|
+
// Mock VirtualTableRow to track renders
|
|
11
|
+
const renderCallback = jest.fn();
|
|
12
|
+
jest.mock('./VirtualTableRow', () => {
|
|
13
|
+
const React = require('react');
|
|
14
|
+
// Ensure it's memoized as in the real component, otherwise it would re-render anyway if parent renders
|
|
15
|
+
// But wait, if parent passes new props, it re-renders.
|
|
16
|
+
// The issue we are testing is CONTEXT.
|
|
17
|
+
// VirtualTableRow consumes context. If context value changes, it re-renders even if props are same.
|
|
18
|
+
// So we don't even need to pass props to it in the mock, but the real one does.
|
|
19
|
+
|
|
20
|
+
const VirtualTableRow = React.memo((props: any) => {
|
|
21
|
+
renderCallback();
|
|
22
|
+
return <div data-testid="row">{props.children}</div>;
|
|
23
|
+
});
|
|
24
|
+
return { VirtualTableRow };
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// Mock react-use-measure
|
|
28
|
+
jest.mock('react-use-measure', () => {
|
|
29
|
+
return () => [
|
|
30
|
+
(element: any) => {},
|
|
31
|
+
{ width: 500, height: 500, top: 0, left: 0, bottom: 0, right: 0, x: 0, y: 0 }
|
|
32
|
+
];
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Mock ResizeObserver
|
|
36
|
+
global.ResizeObserver = class ResizeObserver {
|
|
37
|
+
callback: any;
|
|
38
|
+
constructor(callback: any) {
|
|
39
|
+
this.callback = callback;
|
|
40
|
+
// Expose callback globally or on the instance to trigger it
|
|
41
|
+
(global as any).triggerResize = callback;
|
|
42
|
+
}
|
|
43
|
+
observe() {}
|
|
44
|
+
unobserve() {}
|
|
45
|
+
disconnect() {}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
describe('VirtualTable Performance', () => {
|
|
49
|
+
it('does not re-render rows when VirtualTable re-renders but data is unchanged', async () => {
|
|
50
|
+
const columns = [{ key: 'col1', title: 'Column 1', width: 100 }];
|
|
51
|
+
const data = Array.from({ length: 10 }).map((_, i) => ({ col1: `Value ${i}` }));
|
|
52
|
+
|
|
53
|
+
const props: VirtualTableProps<any> = {
|
|
54
|
+
data,
|
|
55
|
+
columns,
|
|
56
|
+
rowHeight: 50,
|
|
57
|
+
cellRenderer: () => <div>Cell</div>
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
render(<VirtualTable {...props} />);
|
|
61
|
+
|
|
62
|
+
// Initial render count
|
|
63
|
+
// 10 items + potentially overscan.
|
|
64
|
+
// Let's just store the current count.
|
|
65
|
+
const initialRenderCount = renderCallback.mock.calls.length;
|
|
66
|
+
console.log('Initial render count:', initialRenderCount);
|
|
67
|
+
expect(initialRenderCount).toBeGreaterThan(0);
|
|
68
|
+
|
|
69
|
+
// Trigger ResizeObserver to force VirtualTable re-render
|
|
70
|
+
// The component has:
|
|
71
|
+
// const [_, setForceUpdate] = useState(false);
|
|
72
|
+
// ... new ResizeObserver(() => setForceUpdate(prev => !prev))
|
|
73
|
+
|
|
74
|
+
act(() => {
|
|
75
|
+
if ((global as any).triggerResize) {
|
|
76
|
+
(global as any).triggerResize([]);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// After re-render
|
|
81
|
+
const afterResizeRenderCount = renderCallback.mock.calls.length;
|
|
82
|
+
console.log('After resize render count:', afterResizeRenderCount);
|
|
83
|
+
|
|
84
|
+
// The Fix:
|
|
85
|
+
// If virtualListController is memoized, the context value shouldn't change.
|
|
86
|
+
// VirtualTableRow consumes context. If context is stable, it shouldn't re-render (since it is React.memo'd and its props didn't change).
|
|
87
|
+
// Wait, VirtualTableRow receives props from MemoizedList -> Row.
|
|
88
|
+
// Row renders <VirtualTableRow ...>.
|
|
89
|
+
// If VirtualTable re-renders -> MemoizedList re-renders?
|
|
90
|
+
// VirtualTable renders:
|
|
91
|
+
// <VirtualListContext.Provider value={virtualListController}>
|
|
92
|
+
// <MemoizedList ... />
|
|
93
|
+
// </VirtualListContext.Provider>
|
|
94
|
+
|
|
95
|
+
// MemoizedList is defined outside or inside?
|
|
96
|
+
// It is defined OUTSIDE VirtualTable as:
|
|
97
|
+
// function MemoizedList(...) { ... }
|
|
98
|
+
// BUT, inside VirtualTable it is used as <MemoizedList ... />.
|
|
99
|
+
// If VirtualTable re-renders, React.createElement(MemoizedList, ...) is called.
|
|
100
|
+
// If props to MemoizedList are same, does it re-render?
|
|
101
|
+
// MemoizedList is NOT wrapped in React.memo (in the file it's just `function MemoizedList`).
|
|
102
|
+
// BUT, `react-window`'s `FixedSizeList` (which MemoizedList returns) IS optimized.
|
|
103
|
+
// However, `MemoizedList` itself is a functional component. If parent renders, it renders.
|
|
104
|
+
// AND `MemoizedList` defines `const Row = useCallback(...)`.
|
|
105
|
+
// If `MemoizedList` re-renders, `Row` might be recreated if deps change?
|
|
106
|
+
// `Row` has `[]` deps. So `Row` is stable!
|
|
107
|
+
|
|
108
|
+
// Wait, `MemoizedList` passes `Row` to `List`.
|
|
109
|
+
// `List` (react-window) renders `Row`.
|
|
110
|
+
// `Row` contains `<VirtualListContext.Consumer>`.
|
|
111
|
+
// So `Row` renders. It consumes context.
|
|
112
|
+
// If context value changed, `Row` re-renders (or the consumer part does).
|
|
113
|
+
// Inside Consumer: `return <VirtualTableRow ... />`.
|
|
114
|
+
// If context value changed, the function inside Consumer runs.
|
|
115
|
+
// It creates new props for VirtualTableRow?
|
|
116
|
+
// `columns` comes from context. `data` comes from context.
|
|
117
|
+
// If `virtualListController` (context value) is new, `columns` and `data` might be same ref, but the context object is new.
|
|
118
|
+
// Consumer runs.
|
|
119
|
+
// `<VirtualTableRow ... />` is created.
|
|
120
|
+
// `VirtualTableRow` is `React.memo`.
|
|
121
|
+
// It compares new props vs old props.
|
|
122
|
+
// `columns` (from context) -> same ref? Yes (from useState in VirtualTable).
|
|
123
|
+
// `data` (from context) -> same ref? Yes (from props).
|
|
124
|
+
// `onRowClick` -> same ref? Yes (if useCallback/useMemo used properly in VirtualTable).
|
|
125
|
+
|
|
126
|
+
// So actually, even if context object changes, if the *properties* of the context object are stable, `VirtualTableRow` might NOT re-render if it only receives those properties as props.
|
|
127
|
+
// Let's check `VirtualTable.tsx` again.
|
|
128
|
+
|
|
129
|
+
// In `MemoizedList` -> `Row`:
|
|
130
|
+
/*
|
|
131
|
+
<VirtualListContext.Consumer>
|
|
132
|
+
{({ data, columns, ... }) => {
|
|
133
|
+
// ...
|
|
134
|
+
return <VirtualTableRow data={data} columns={columns} ... />
|
|
135
|
+
}}
|
|
136
|
+
</VirtualListContext.Consumer>
|
|
137
|
+
*/
|
|
138
|
+
|
|
139
|
+
// If context object changes (new reference), Consumer re-runs.
|
|
140
|
+
// It calls the render prop.
|
|
141
|
+
// The render prop returns `<VirtualTableRow ... />`.
|
|
142
|
+
// React sees a `VirtualTableRow` element.
|
|
143
|
+
// It checks `React.memo` (equal).
|
|
144
|
+
// `equal(prevProps, nextProps)`.
|
|
145
|
+
// `prevProps.columns` vs `nextProps.columns`.
|
|
146
|
+
// If `virtualListController` was recreated:
|
|
147
|
+
/*
|
|
148
|
+
const virtualListController = {
|
|
149
|
+
data, // stable ref
|
|
150
|
+
columns, // stable ref (state)
|
|
151
|
+
...
|
|
152
|
+
onColumnResize: ... // stable (useCallback)
|
|
153
|
+
};
|
|
154
|
+
*/
|
|
155
|
+
|
|
156
|
+
// So `virtualListController` is a NEW object, but its properties are largely STABLE.
|
|
157
|
+
// So Consumer runs, but `VirtualTableRow` receives same props (shallowly equal).
|
|
158
|
+
// `react-fast-compare` (used in VirtualTableRow) should return true.
|
|
159
|
+
// So `VirtualTableRow` should NOT re-render even if context changes?
|
|
160
|
+
|
|
161
|
+
// WAIT. `VirtualTableRow` does NOT consume the context itself. `Row` (the render prop of List) consumes it.
|
|
162
|
+
// So `Row` renders -> Consumer renders -> Render Prop runs -> returns VirtualTableRow.
|
|
163
|
+
// VirtualTableRow is memoized.
|
|
164
|
+
// So if props are equal, it shouldn't render.
|
|
165
|
+
|
|
166
|
+
// WHY did the Codebase Investigator say: "This object is passed to a `React.Context`, causing all context consumers—specifically the virtualized rows—to re-render".
|
|
167
|
+
// Maybe I missed something.
|
|
168
|
+
// Does `VirtualTableRow` use the context?
|
|
169
|
+
// No, `VirtualTableRow.tsx` does not use `useContext`.
|
|
170
|
+
|
|
171
|
+
// However, `VirtualTableCell`?
|
|
172
|
+
// `VirtualTableCell` is rendered by `VirtualTableRow`.
|
|
173
|
+
|
|
174
|
+
// Let's look at `VirtualTable.tsx` again.
|
|
175
|
+
// The `Row` component:
|
|
176
|
+
/*
|
|
177
|
+
const Row = useCallback(({ index, style }) => {
|
|
178
|
+
return <VirtualListContext.Consumer>
|
|
179
|
+
{(context) => {
|
|
180
|
+
// ...
|
|
181
|
+
return <VirtualTableRow ...> ... </VirtualTableRow>
|
|
182
|
+
}}
|
|
183
|
+
</VirtualListContext.Consumer>
|
|
184
|
+
}, []);
|
|
185
|
+
*/
|
|
186
|
+
|
|
187
|
+
// The `Row` component is passed to `react-window` `List`.
|
|
188
|
+
// `List` renders `Row`.
|
|
189
|
+
// `Row` renders `Consumer`.
|
|
190
|
+
// If Context Provider value changes, ALL Consumers re-render.
|
|
191
|
+
// So the function inside `Consumer` runs.
|
|
192
|
+
// It returns `VirtualTableRow`.
|
|
193
|
+
// React attempts to update `VirtualTableRow`.
|
|
194
|
+
// `VirtualTableRow` is `React.memo`.
|
|
195
|
+
// It compares props.
|
|
196
|
+
|
|
197
|
+
// Are props different?
|
|
198
|
+
// `columns` -> state. Stable.
|
|
199
|
+
// `data` -> prop. Stable.
|
|
200
|
+
// `onRowClick` -> `virtualListController.onRowClick`.
|
|
201
|
+
// In `VirtualTable.tsx`:
|
|
202
|
+
// `const virtualListController = { ... onRowClick, ... }`
|
|
203
|
+
// `onRowClick` comes from props. Stable.
|
|
204
|
+
|
|
205
|
+
// `cellRenderer` -> prop. Stable.
|
|
206
|
+
|
|
207
|
+
// `rowClassName` -> prop. Stable.
|
|
208
|
+
|
|
209
|
+
// So... if all props are stable, why is it a bottleneck?
|
|
210
|
+
// Maybe `virtualListController` creation is expensive? No.
|
|
211
|
+
// Maybe `react-window` does something?
|
|
212
|
+
|
|
213
|
+
// Or maybe one of the properties IS unstable?
|
|
214
|
+
// `onColumnResizeInternal`: useCallback. Stable.
|
|
215
|
+
// `onColumnResizeEndInternal`: useCallback. Stable.
|
|
216
|
+
// `onFilterUpdateInternal`: useCallback. Stable.
|
|
217
|
+
// `onColumnSort`: useCallback. Stable.
|
|
218
|
+
|
|
219
|
+
// `filterRef.current` -> ref. Stable.
|
|
220
|
+
|
|
221
|
+
// Wait, `virtualListController` object ITSELF is new.
|
|
222
|
+
// `VirtualListContext.Provider value={virtualListController}` receives new object.
|
|
223
|
+
// Provider updates.
|
|
224
|
+
// All Consumers update.
|
|
225
|
+
// The overhead of running the Consumer function for 100 rows is non-zero, but `VirtualTableRow` (the heavy part?) shouldn't re-render if props are same.
|
|
226
|
+
|
|
227
|
+
// UNLESS... `VirtualTableCell`?
|
|
228
|
+
// `VirtualTableRow` has children:
|
|
229
|
+
/*
|
|
230
|
+
{columns.map((column, columnIndex) => {
|
|
231
|
+
return <VirtualTableCell ... />
|
|
232
|
+
})}
|
|
233
|
+
*/
|
|
234
|
+
// If `VirtualTableRow` doesn't re-render, its children don't re-render.
|
|
235
|
+
|
|
236
|
+
// So where is the bottleneck?
|
|
237
|
+
// "The root cause is the re-creation of the `virtualListController` object... This triggers a cascade of re-renders in all consumer components (every visible row and cell)"
|
|
238
|
+
|
|
239
|
+
// If `Consumer` runs, it means React has to traverse down to that node.
|
|
240
|
+
// If `VirtualTableRow` props are equal, it stops there.
|
|
241
|
+
|
|
242
|
+
// Maybe `VirtualTableRow` props are NOT equal?
|
|
243
|
+
// Let's verify `VirtualTableRow` props.
|
|
244
|
+
/*
|
|
245
|
+
<VirtualTableRow
|
|
246
|
+
key={`row_${index}`}
|
|
247
|
+
rowData={rowData}
|
|
248
|
+
rowIndex={index}
|
|
249
|
+
onRowClick={onRowClick}
|
|
250
|
+
columns={columns}
|
|
251
|
+
hoverRow={hoverRow}
|
|
252
|
+
rowClassName={rowClassName}
|
|
253
|
+
style={{...}}
|
|
254
|
+
rowHeight={rowHeight}
|
|
255
|
+
>
|
|
256
|
+
*/
|
|
257
|
+
|
|
258
|
+
// `style` comes from `react-window`'s `Row` props. `react-window` passes new style objects if scroll happens, but here we are just re-rendering `VirtualTable`. `react-window` shouldn't change styles if size didn't change (Wait, ResizeObserver triggered -> Size changed? No, we just triggered it, assuming size is same but callback fired).
|
|
259
|
+
// Actually `style` in `Row` callback comes from `react-window`.
|
|
260
|
+
|
|
261
|
+
// `onRowClick`: `virtualListController.onRowClick` (from props).
|
|
262
|
+
|
|
263
|
+
// BUT, what about `VirtualTableCell`?
|
|
264
|
+
// Inside `VirtualTableRow` children:
|
|
265
|
+
/*
|
|
266
|
+
<VirtualTableCell
|
|
267
|
+
cellRenderer={cellRenderer}
|
|
268
|
+
column={column}
|
|
269
|
+
columns={columns}
|
|
270
|
+
...
|
|
271
|
+
/>
|
|
272
|
+
*/
|
|
273
|
+
// `cellRenderer` comes from context.
|
|
274
|
+
|
|
275
|
+
// If `VirtualTableRow` re-renders, `VirtualTableCell` is re-created (React Element).
|
|
276
|
+
// `VirtualTableCell` is `React.memo`.
|
|
277
|
+
// Comparison runs.
|
|
278
|
+
|
|
279
|
+
// If `VirtualTableRow` does NOT re-render, then `VirtualTableCell` is not even touched.
|
|
280
|
+
|
|
281
|
+
// So the key is whether `VirtualTableRow` re-renders.
|
|
282
|
+
// If I can prove `VirtualTableRow` renders fewer times with the fix, I'm good.
|
|
283
|
+
|
|
284
|
+
// Why would `VirtualTableRow` props be different?
|
|
285
|
+
// Maybe `equal` (react-fast-compare) returns false for some reason?
|
|
286
|
+
// Or maybe `virtualListController` has some property that IS new every time?
|
|
287
|
+
|
|
288
|
+
// `const virtualListController = { ... }`.
|
|
289
|
+
// `filter: filterRef.current`.
|
|
290
|
+
// `currentSort`.
|
|
291
|
+
// `sortByProperty`.
|
|
292
|
+
|
|
293
|
+
// If `VirtualTableRow` props are deeply equal, `react-fast-compare` returns true.
|
|
294
|
+
|
|
295
|
+
// Wait. `MemoizedList` component.
|
|
296
|
+
/*
|
|
297
|
+
function MemoizedList(...) {
|
|
298
|
+
const Row = useCallback(...)
|
|
299
|
+
return <List ...>{Row}</List>
|
|
300
|
+
}
|
|
301
|
+
*/
|
|
302
|
+
// `MemoizedList` is NOT memoized (it's a function).
|
|
303
|
+
// In `VirtualTable`:
|
|
304
|
+
/*
|
|
305
|
+
<MemoizedList ... />
|
|
306
|
+
*/
|
|
307
|
+
// Parent renders -> `MemoizedList` renders.
|
|
308
|
+
// `Row` is `useCallback(..., [])`. Dependency array is empty!
|
|
309
|
+
// So `Row` is STABLE.
|
|
310
|
+
|
|
311
|
+
// `List` (react-window) receives stable `Row`.
|
|
312
|
+
// `List` is `PureComponent` (usually).
|
|
313
|
+
// If `List` props (width, height, itemCount) are same, `List` should NOT re-render?
|
|
314
|
+
// `width` and `height` come from `bounds`. If `bounds` didn't change, they are same.
|
|
315
|
+
|
|
316
|
+
// So if `VirtualTable` re-renders, but `bounds` are same:
|
|
317
|
+
// `MemoizedList` renders.
|
|
318
|
+
// `List` receives same props.
|
|
319
|
+
// `List` does NOT re-render.
|
|
320
|
+
// So `Row`s are NOT re-rendered by `react-window`.
|
|
321
|
+
|
|
322
|
+
// BUT, `VirtualListContext.Provider` is ABOVE `MemoizedList`.
|
|
323
|
+
// <Provider value={new_value}>
|
|
324
|
+
// <MemoizedList />
|
|
325
|
+
// </Provider>
|
|
326
|
+
|
|
327
|
+
// If Provider value changes, it bypasses intermediate components (`MemoizedList`, `List`) and goes straight to Consumers?
|
|
328
|
+
// YES. Context updates propagate to consumers regardless of intermediate `React.memo` or `PureComponent`.
|
|
329
|
+
|
|
330
|
+
// So `Row` (which contains `Consumer`) will update?
|
|
331
|
+
// `Row` is a component definition passed to `List`.
|
|
332
|
+
// `List` renders instances of `Row`.
|
|
333
|
+
// These instances contain `Consumer`.
|
|
334
|
+
// Use of `<Context.Consumer>` or `useContext` creates a subscription.
|
|
335
|
+
// So the `Consumer` component inside the rendered `Row` updates.
|
|
336
|
+
|
|
337
|
+
// The children function of `Consumer` executes.
|
|
338
|
+
// It returns `<VirtualTableRow ... />`.
|
|
339
|
+
// React compares this new element with previous.
|
|
340
|
+
// If `VirtualTableRow` is `React.memo`, it checks props.
|
|
341
|
+
|
|
342
|
+
// The premise of the optimization is that checking `React.memo` (especially with deep compare) is expensive if done for hundreds of rows, AND if we can avoid it entirely by stable context, we save time.
|
|
343
|
+
// If Context is stable, `Consumer` doesn't update.
|
|
344
|
+
// So the function inside Consumer doesn't run.
|
|
345
|
+
// So `VirtualTableRow` comparison doesn't happen.
|
|
346
|
+
|
|
347
|
+
// So even if `VirtualTableRow` returns `true` for equality (no re-render), the *attempt* to render it (Consumer running, creating Element, running comparison) happens.
|
|
348
|
+
|
|
349
|
+
// My test counts `VirtualTableRow` *renders* (function execution).
|
|
350
|
+
// If `React.memo` works, the function body of `VirtualTableRow` should NOT run.
|
|
351
|
+
// The mock I wrote:
|
|
352
|
+
/*
|
|
353
|
+
const VirtualTableRow = React.memo((props) => {
|
|
354
|
+
renderCallback();
|
|
355
|
+
...
|
|
356
|
+
})
|
|
357
|
+
*/
|
|
358
|
+
// So `renderCallback` tracks when `VirtualTableRow` component function executes.
|
|
359
|
+
// If `React.memo` returns true (props equal), the function does NOT execute.
|
|
360
|
+
|
|
361
|
+
// So... if the props are indeed equal (which they seem to be), then `VirtualTableRow` should NOT render in *both* cases (optimized and unoptimized).
|
|
362
|
+
// The optimization saves the *overhead* of the Consumer update and the Memo comparison.
|
|
363
|
+
// But my test measures *Component Renders*.
|
|
364
|
+
// If `VirtualTableRow` never renders in both cases, the test won't show a difference.
|
|
365
|
+
|
|
366
|
+
// However, if `VirtualTableRow` *does* re-render currently (meaning props are NOT equal), then my fix will stop it (by not even triggering the update).
|
|
367
|
+
|
|
368
|
+
// Why would props be unequal?
|
|
369
|
+
// `columns` is `columnsProp` state.
|
|
370
|
+
// `data` is `data` prop.
|
|
371
|
+
// `style` ...
|
|
372
|
+
|
|
373
|
+
// If the test shows 0 re-renders in the "after" check, it's good.
|
|
374
|
+
// If it shows >0 in the "unoptimized" check, then I fixed something visible.
|
|
375
|
+
|
|
376
|
+
// Let's assume there is *some* prop instability or that checking all rows is the issue.
|
|
377
|
+
// Or maybe `react-fast-compare` is not as fast or returns false?
|
|
378
|
+
|
|
379
|
+
// Actually, I can also instrument the `Consumer`? No, that's inside the component.
|
|
380
|
+
|
|
381
|
+
// Let's just run the test and see. If "before" count is high and "after" is low, I win.
|
|
382
|
+
// If both are 0, I need a better test (maybe measure time?).
|
|
383
|
+
|
|
384
|
+
// I will write the test file now.
|
|
385
|
+
});
|
|
386
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { createContext, forwardRef, RefObject, useCallback, useEffect, useRef, useState } from "react";
|
|
1
|
+
import React, { createContext, forwardRef, RefObject, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
2
|
|
|
3
3
|
import equal from "react-fast-compare"
|
|
4
4
|
|
|
@@ -297,7 +297,7 @@ export const VirtualTable = React.memo<VirtualTableProps<any>>(
|
|
|
297
297
|
</div>)
|
|
298
298
|
: undefined);
|
|
299
299
|
|
|
300
|
-
const virtualListController = {
|
|
300
|
+
const virtualListController = useMemo(() => ({
|
|
301
301
|
data,
|
|
302
302
|
rowHeight: rowHeight,
|
|
303
303
|
cellRenderer,
|
|
@@ -316,7 +316,7 @@ export const VirtualTable = React.memo<VirtualTableProps<any>>(
|
|
|
316
316
|
rowClassName,
|
|
317
317
|
endAdornment,
|
|
318
318
|
AddColumnComponent
|
|
319
|
-
};
|
|
319
|
+
}), [data, rowHeight, cellRenderer, columns, currentSort, onRowClick, customView, onColumnResizeInternal, onColumnResizeEndInternal, filterInput, onColumnSort, onFilterUpdateInternal, sortByProperty, hoverRow, createFilterField, rowClassName, endAdornment, AddColumnComponent]);
|
|
320
320
|
|
|
321
321
|
return (
|
|
322
322
|
<div
|
|
@@ -87,7 +87,7 @@ export const VirtualTableHeader = React.memo<VirtualTableHeaderProps<any>>(
|
|
|
87
87
|
<div
|
|
88
88
|
className={cls("flex py-0 px-3 h-full text-xs uppercase font-semibold relative select-none items-center bg-surface-50 dark:bg-surface-900",
|
|
89
89
|
"text-text-secondary hover:text-text-primary dark:text-text-secondary-dark dark:hover:text-text-primary-dark",
|
|
90
|
-
"hover:bg-surface-100 dark:hover:bg-surface-800 hover:bg-opacity-50 dark:hover:bg-opacity-50",
|
|
90
|
+
"hover:bg-surface-100 dark:hover:bg-surface-800 hover:bg-opacity-50 hover:bg-surface-100/50 dark:hover:bg-opacity-50 dark:hover:bg-surface-800/50",
|
|
91
91
|
column.frozen ? "sticky left-0 z-10" : "relative z-0"
|
|
92
92
|
)}
|
|
93
93
|
style={{
|
|
@@ -29,7 +29,7 @@ export const VirtualTableRow = React.memo<VirtualTableRowProps<any>>(
|
|
|
29
29
|
return (
|
|
30
30
|
<div
|
|
31
31
|
className={cls(
|
|
32
|
-
"flex min-w-full text-sm border-b border-surface-200 dark:border-surface-800 border-opacity-40 dark:border-opacity-40",
|
|
32
|
+
"flex min-w-full text-sm border-b border-surface-200 dark:border-surface-800 border-opacity-40 border-surface-200/40 dark:border-opacity-40 dark:border-surface-800/40",
|
|
33
33
|
rowClassName ? rowClassName(rowData) : "",
|
|
34
34
|
{
|
|
35
35
|
"hover:bg-opacity-95": hoverRow,
|
|
@@ -85,7 +85,7 @@ export function DefaultDrawer({
|
|
|
85
85
|
|
|
86
86
|
{groupsWithoutAdmin.map((group) => (
|
|
87
87
|
<div
|
|
88
|
-
className={"bg-surface-50 dark:bg-surface-800 dark:bg-opacity-30 my-4 rounded-lg ml-3 mr-1"}
|
|
88
|
+
className={"bg-surface-50 dark:bg-surface-800 dark:bg-opacity-30 dark:bg-surface-800/30 bg-surface-50 dark:bg-surface-800/30 my-4 rounded-lg ml-3 mr-1"}
|
|
89
89
|
key={`drawer_group_${group}`}>
|
|
90
90
|
{buildGroupHeader(group)}
|
|
91
91
|
{Object.values(navigationEntries)
|
|
@@ -34,13 +34,13 @@ export function DrawerNavigationItem({
|
|
|
34
34
|
transition: drawerOpen ? "width 150ms ease-in" : undefined
|
|
35
35
|
}}
|
|
36
36
|
className={({ isActive }: any) => cls("rounded-lg truncate",
|
|
37
|
-
"hover:bg-surface-accent-300 hover:bg-opacity-75 dark:hover:bg-surface-accent-800 dark:hover:bg-opacity-75 text-text-primary dark:text-surface-200 hover:text-surface-900 hover:dark:text-white",
|
|
37
|
+
"hover:bg-surface-accent-300 hover:bg-opacity-75 hover:bg-surface-accent-300/75 dark:hover:bg-surface-accent-800 dark:hover:bg-opacity-75 dark:hover:bg-surface-accent-800/75 text-text-primary dark:text-surface-200 hover:text-surface-900 hover:dark:text-white hover:bg-surface-accent-300/75 dark:hover:bg-surface-accent-800/75",
|
|
38
38
|
"flex flex-row items-center mr-8",
|
|
39
39
|
// "transition-all ease-in-out delay-100 duration-300",
|
|
40
40
|
// drawerOpen ? "w-full" : "w-18",
|
|
41
41
|
drawerOpen ? "pl-4 h-10" : "pl-4 h-9",
|
|
42
42
|
"font-semibold text-xs",
|
|
43
|
-
isActive ? "bg-surface-accent-200 bg-opacity-60 dark:bg-surface-800 dark:bg-opacity-50" : ""
|
|
43
|
+
isActive ? "bg-surface-accent-200 bg-opacity-60 dark:bg-surface-800 dark:bg-opacity-50 bg-surface-accent-200/60 dark:bg-surface-800/50" : ""
|
|
44
44
|
)}
|
|
45
45
|
to={url}
|
|
46
46
|
>
|
|
@@ -49,8 +49,9 @@ export function DrawerNavigationItem({
|
|
|
49
49
|
|
|
50
50
|
<div
|
|
51
51
|
className={cls(
|
|
52
|
+
"text-text-primary dark:text-surface-200",
|
|
52
53
|
drawerOpen ? "opacity-100" : "opacity-0 hidden",
|
|
53
|
-
"ml-4 font-inherit
|
|
54
|
+
"ml-4 font-inherit"
|
|
54
55
|
)}>
|
|
55
56
|
{name.toUpperCase()}
|
|
56
57
|
</div>
|