Repository navigation
fix(Table): key its column and plugin caches on identities #10940
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b18ca6f
fix(Table): keep its column and plugin caches at commit
vjeux 7998c38
Merge branch 'main' into fix/table-caches-at-commit
vjeux 3a98d1f
fix(Table): key the column and plugin caches on identities
vjeux 1fe0959
docs(Table): cite the one-time initialization rule by its record id
vjeux 51bbf3c
Merge branch 'main' into fix/table-caches-at-commit
vjeux File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@astryxdesign/core': patch | ||
| --- | ||
|
|
||
| [fix] Table keeps one array for each list of columns, and for each list of plugins, compared by identity. A render React throws away, as a suspended transition does, can no longer replace the array the table last displayed. The next committed render reuses the array, so rows skip rendering when the columns and plugins match the committed ones. `useBaseTablePlugins` also keeps its array when the base plugins come in a new array of the same plugins. A column plugin with its own render-time cache, such as the tree plugin, still re-renders every row. | ||
|
|
||
| @vjeux |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,6 @@ import { | |
| memo, | ||
| useId, | ||
| useMemo, | ||
| useRef, | ||
| type ReactElement, | ||
| type ReactNode, | ||
| type Ref, | ||
|
|
@@ -72,6 +71,7 @@ import {TableHeader} from './TableHeader'; | |
| import {TableBody} from './TableBody'; | ||
| import {mergeProps} from '../utils'; | ||
| import {useMergedRefs} from '../hooks/useMergedRefs'; | ||
| import {internByIdentity} from './internByIdentity'; | ||
| import { | ||
| readsRowCount, | ||
| readsRowIndex, | ||
|
|
@@ -187,25 +187,6 @@ function applyRowPlugins< | |
| // Stable empty array to avoid creating new reference on each render | ||
| const EMPTY_PLUGINS: TablePlugin<Record<string, unknown>>[] = []; | ||
|
|
||
| /** | ||
| * Shallow-compare two arrays by element identity. | ||
| * Used to stabilize the resolved columns array across renders. | ||
| */ | ||
| function areArraysShallowEqual<T>(a: T[], b: T[]): boolean { | ||
| if (a === b) { | ||
| return true; | ||
| } | ||
| if (a.length !== b.length) { | ||
| return false; | ||
| } | ||
| for (let i = 0; i < a.length; i++) { | ||
| if (a[i] !== b[i]) { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| interface TableRowProps<T extends Record<string, unknown>> { | ||
| item: T; | ||
| rowIndex: number; | ||
|
|
@@ -608,11 +589,9 @@ function BaseTableInner<T extends Record<string, unknown>>({ | |
| // new array on every call, but if the contents haven't changed, we | ||
| // reuse the previous reference. This prevents MemoizedTableRow from | ||
| // re-rendering all rows when the column array is structurally identical. | ||
| const resolvedColumnsRef = useRef(transformedColumns); | ||
| if (!areArraysShallowEqual(resolvedColumnsRef.current, transformedColumns)) { | ||
| resolvedColumnsRef.current = transformedColumns; | ||
| } | ||
| const resolvedColumns = resolvedColumnsRef.current; | ||
| // Every render with the same columns gets one array, so a render React | ||
| // discards cannot leave another. No state or ref is written during render. | ||
|
Comment on lines
+592
to
+593
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-blocking (comment style): this now sits under the old four-line comment, which still says "we reuse the previous reference", and its last sentence is passive. One comment can keep only the reason: // transformColumns returns a new array on each call. One array per list of
// columns lets MemoizedTableRow skip rows, even after a render React discards. |
||
| const resolvedColumns = internByIdentity(transformedColumns); | ||
| const headerRowCount = mode === 'data' && resolvedColumns.length > 0 ? 1 : 0; | ||
| const config = getTableVirtualizationConfig(virtualization); | ||
| const windowFallbackReason = useMemo(() => { | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.