Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/table-caches-at-commit.md
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
9 changes: 8 additions & 1 deletion docs/specs/components/Table/Table.spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ Consumer migration instructions belong in consumer docs and release notes.
- Canonical key resolution and opt-in validity, row classification, declared
whole-row conflict handling, immutable transform context and pre-cell render planning.
- The coordinated viewport, logical positions and parent row-paint resolution.
- `Table/internByIdentity.ts`: keeps resolved columns and merged plugins stable
across renders by input identity, with no state or ref; each entry is written
once, on first sight of an identity path, and never changed
(`architecture:react-component-runtime` INV17's lazy one-time
Comment thread
astracat-bot[bot] marked this conversation as resolved.
Resolved
initialization), so a render React discards can only add entries, never
change the array a later render gets; BaseTable and useBaseTablePlugins import
it; no existing helper keys a list by its items' identities.

**Does not own / non-goals**

Expand Down Expand Up @@ -458,7 +465,7 @@ for this aggregate ownership.
| FR7 | `plugins/rowExpansion/useTableRowExpansion.test.tsx` plus source inspection; for the icon slot, a `useTableRowExpansion.test.tsx` slot suite and the slot inventory test | Collapsed, expanded, and non-expandable rows; the theme slot unset, a slot function, `null`, and a size request | Removing the Expansion control, conditional detail panel, captured-count `colSpan`, or ARIA state fails existing assertions in the covered plugin order; later column transforms, delegated Icon target placement, and untargeted panel wrappers remain source-inspected. For the icon slot, ignoring the theme slot or its `expanded` state, dropping the turn, or letting `null` remove the control, its name, or its toggling fails. | `audit:Table/anatomy` |
| FR8 | `Table.test.tsx` empty-state suite plus EmptyState public target metadata | Default, custom, disabled, and non-empty | Removing conditional empty behavior fails existing assertions; default EmptyState delegation remains source-inspected. | `audit:Table/anatomy` |
| FR9-FR11 | `Table.test.tsx`, `types.ts`, `BaseTable.tsx`, and `useBaseTablePlugins.ts`; `useTableColumnResize.test.tsx` "the handle never adds to its column header\'s name (AR1)" and `TableColumnResizeName.a11y.chromium.spec.ts` for the `overlay` slot\'s name | Built-in plus known and custom named plugins; every transform phase | Sequential composition, base-before-user behavior, transform application, and slot output have focused coverage; complete known-name sorting, phase order, exception continuation, and context nesting remain source-inspected. | `audit:Table/plugins` |
| FR12, PR1 | `Table.perf.test.tsx` plus `useBaseTablePlugins.ts` source inspection | Same plugin references, recreated record, and changed plugin value | Unchanged plugin values must preserve the resolved array and representative no-op row-update budgets; focused named-record identity coverage remains partial. | `audit:Table/performance` |
| FR12, PR1 | `Table.perf.test.tsx` and `internByIdentity.test.ts`, plus `useBaseTablePlugins.ts` and `internByIdentity.ts` source inspection | Same plugin references, recreated record, and changed plugin value | Unchanged plugin values must preserve the resolved array and representative no-op row-update budgets; focused named-record identity coverage remains partial. | `audit:Table/performance` |
| FR13, PR3 | `Table.test.tsx`, `plugins/columnResize/useTableColumnResize.test.tsx`, `plugins/stickyColumns/useTableStickyColumns.test.tsx`, and `Table.stories.tsx` ResponsiveScroll play assertions; for the windowed row-position floor, `plugins/rowIndex/useTableRowIndex.test.tsx` and a real-browser windowing check, including an append from 999 to 1,000 rows while scrolled to the end, re-measurement after a font, theme, density or host-inset change, and a pinned column after a widened row-number column keeping its inline start at the end of the columns before it (an overlap fails) | Width-less columns with empty, short, and long-token rows; mixed explicit widths; pinned columns; narrow and fitting containers; windowed numbering at each density's first 48px overflow: compact row 10,000, balanced row 1,000, spacious row 100 | Removing the 60px floor, deriving it from row content, changing explicit width semantics, desynchronizing resize bounds or sticky offsets, or preventing the existing Scroll region from activating fails focused unit or real-browser geometry assertions. A windowed number column that clips a number, falls back when a longer number mounts or its font or padding changes (host inset included), or narrows below its authored width, or an unwindowed one that widens, fails. | `audit:Table/layout` |
| FR14 | `__tests__/TableRowGlide.a11y.browser.spec.ts` screenshot checks of the divider mid-glide, in pinned columns, and under an open detail panel; `plugins/rowExpansion/useTableRowExpansion.glide.test.tsx` for the divider an open panel carries | a theme with a custom divider colour; an app override of a row's border; both mid-glide and on a pinned cell; an open detail panel's divider under the same theme and override | a divider whose width, style or colour differs from the row's border, or that drops a theme or app override, fails | `audit:Table/theming` |
| FR15 | `plugins/rowExpansion/useTableRowExpansion.glide.test.tsx` and `__tests__/TableRowGlide.a11y.browser.spec.ts`: row expansion with and without `animatedLayout`, plus source inspection of the panel's entrance and its hide on close | open and close with the handle; without it; reduced motion under a coarse and a fine pointer; a glyph turn beside the glide; a `dividers="grid"` and a `dividers="columns"` table with the option; a muted panel mid-open | rows that jump with the handle in a table without column lines, a closing panel that animates or leaves its space empty before the rows arrive, a panel and rows on different motion, a glyph on its own timing beside the glide, travel under reduced motion, or any motion without the handle a table with column lines that glides or animates its panel, or one whose glyph does not keep its own turn, fails | `audit:Table/plugins` |
Expand Down
29 changes: 4 additions & 25 deletions packages/core/src/Table/BaseTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
memo,
useId,
useMemo,
useRef,
type ReactElement,
type ReactNode,
type Ref,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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(() => {
Expand Down
Loading