Repository navigation
(prototype) Table windowing: a scroll band on both axes - #11197
humbertovirtudes wants to merge 9 commits into
Conversation
New module:Table/useTableColumnsVirtualization: an opaque capability from initialViewportWidth windows the columns between the pinned start and end runs, using the widths Table layout gives each column at its minimum width, with two overscan columns per side, one retained focused column, native spacer cells, full-table aria-colindex/aria-colcount and a combination with row windowing. component:Table FR18 lets Table.virtualization take one capability or a list of at most one per axis. This diff was generated with AI assistance (Navi). Tags: ai-generated
Table.virtualization accepts a columns capability, alone or in a list with at most one rows capability. Table mounts only the unpinned columns near the inline viewport, plus two overscan columns per side, and keeps the pinned start and end runs mounted. Each column's pitch is the width it renders at the table's minimum width. The header row and every body row render the same inaccessible spacer cells for unmounted columns. While columns window, the table carries aria-colcount and mounted cells carry full-table aria-colindex. The server and first client use the same seed from initialViewportWidth. Inline geometry comes from the shared Table viewport measurement. Unsupported content or structure renders every column with a development warning. With both capabilities, this slice windows the rows and renders every column. The retained focused column, the first-visible-column anchor and windowing both axes together come in later slices. This diff was generated with AI assistance (Navi). Tags: ai-generated
…the first visible column A focused cell whose column leaves the window stays mounted with its original element. Focus leaving the table releases it, focus moving to another cell transfers it, and removing the column returns focus to the Table's scroll area. The header row and every body row render up to three spacers: before the range, between the range and the focused column, and after both. Changes to column order, widths, visibility and pinning keep the first visible column's key and fractional offset. A removed anchor resolves to the next surviving column, then the previous one, then the start. The planner reuses the row windowing focus-return and anchor helpers; the anchor helper gains per-item offsets for columns of varying width. This diff was generated with AI assistance (Navi). Tags: ai-generated
A Table.virtualization list with a rows and a columns capability now windows both axes. The fallback that rendered every column beside row windowing is gone. Each row gap spans the mounted column structure: pinned cells, spacers and mounted cells. A focused cell keeps its row island and its column. Both axes read the one shared viewport subscription. The rows module's mounted-row checks read cells by full-table column position, so pitch, overflow and row-number width checks skip column spacers. A row-number column that windows out keeps its last measured width. The sized columns are memoised, so the column pitches keep their identity across renders when row numbers widen. This diff was generated with AI assistance (Navi). Tags: ai-generated
A measurement prototype, not for merge. The shared windowing module plans a band past each viewport edge instead of a fixed overscan count: on the block axis min(512px, viewport height), on the inline axis min(256px, half the width between the pinned runs). Each window hook reads the one shared geometry source through a banded snapshot reader. It keeps the snapshot it last planned from until that axis's scroll offset moves half a band, or the viewport size, start offset, measured state or revision changes, or an anchor scroll write is pending. React skips a render for an identical snapshot, so a scroll inside the band commits nothing, and a scroll on one axis does not re-run the other axis's plan. Adds deterministic commit-count tests and a Chromium measurement harness. Tests that asserted the four-row or two-column overscan now assert the band. This diff was generated with AI assistance (Navi). Tags: ai-generated
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
…pshot A measurement prototype, not for merge. At 120px per frame the band still committed about three times per frame. A probe in the banded snapshot reader showed content revisions passing it through: each band move mounts rows, the shared measurement then publishes a content revision, and the planner re-planned from the live offset. The banded snapshot now holds the content revision; size, start offset, extent, measured state, layout revision and a pending anchor write still pass through. Validation of newly mounted rows keys on the committed mounted range, so it still runs in the layout effect of the commit that mounts them. This diff was generated with AI assistance (Navi). Tags: ai-generated
A measurement prototype, not for merge. Each axis's band is the smaller of a pixel limit and a fraction of the viewport, held in one private constant per axis so a measurement build can switch it. The defaults are unchanged. This diff was generated with AI assistance (Navi). Tags: ai-generated
While columns window, a row re-rendered every mounted cell whenever the column range changed, because the row takes the new column segments. Each row now keeps the element it built for each mounted column, keyed by the column and valid for the item, row context, plugins, columns, text overflow, row height and cell component it was built from. React skips an identical element, so a range change renders only the cells of entering columns, and a column that leaves drops its element. Tables without column windowing build their cells as before. This diff was generated with AI assistance (Navi). Tags: ai-generated
A measurement prototype, not for merge. The harness takes a pattern subset per variant, rotates the run order across any number of variants, and in its coverage pass counts body cells that rendered: a re-rendered cell gets a new props object, and a skipped one keeps the object it had. This diff was generated with AI assistance (Navi). Tags: ai-generated
There was a problem hiding this comment.
Outcome: approval waits on an engineering owner's spec decision, and two fixes are needed either way.
This prototype replaces Table windowing's fixed overscan with a pixel band, which intentionally changes module:Table/useTableRowsVirtualization FR2, ORD3, PR1 and DEC-1, while the inline band has no governing record on main yet. Approval needs an engineering owner to update that spec for the change or decline the band; an engineering owner, the author included, records the decision by commenting /approve-spec <full head SHA> on this pull request.
Blocking findings:
- First-visible anchoring is lost after a scroll shorter than half a band, because a data change anchors from the stale planned snapshot and the pending scroll write is then dropped, so rows or columns inserted or moved before the viewport shift the content (
useListWindow.ts:225-257,useInlineListWindow.ts:195-219), which contradicts FR8. - The description says first-visible-key anchoring is unchanged and that no correctness regressions were found, but anchoring regresses after short scrolls, so fix it or narrow that claim.
If the band is approved, the Chromium structural-bound specs also need to move to the new PR1 bound.
| // A pending anchor write must see each live offset until it lands. | ||
| const isAnchorPending = tracking?.pending !== undefined; | ||
| const getBandedSnapshot = useMemo( | ||
| () => createBandedBlockSnapshot(geometry, isAnchorPending), | ||
| [geometry, isAnchorPending], | ||
| ); |
There was a problem hiding this comment.
After a scroll shorter than half a band, getBandedSnapshot still returns the old planned snapshot, so a data change anchors from that stale last.plan (line 225). The pending flag then swaps in a pass-through reader, isAwaitingAnchor sees a different live scrollTop, and the anchor is dropped: one row inserted at the top after a 200px scroll leaves scrollTop at 200 (the base moves it to 240). This contradicts FR8. Derive the anchor's first visible index and offset from the live geometry.getSnapshot() with the previous keys and pitch.
| // A pending anchor write must see each live offset until it lands. | ||
| const isAnchorPending = tracking?.pending !== undefined; | ||
| const insets = insetStart + insetEnd; | ||
| const getBandedSnapshot = useMemo( | ||
| () => createBandedInlineSnapshot(geometry, insets, isAnchorPending), | ||
| [geometry, insets, isAnchorPending], | ||
| ); |
There was a problem hiding this comment.
Same anchoring gap on the inline axis: after a scroll under half a band, a column change anchors from the stale planned tracking, and the anchor is then dropped. In the ColumnWindowingFocus story, "Move the first column to the end" after a 100px scroll past the last band move leaves scrollLeft at 2100 and the view jumps 160px (the base moves to 1940 and keeps the same column in place).
There was a problem hiding this comment.
Outcome: approval waits on an engineering owner's spec decision, and three fixes are needed either way.
This prototype intentionally changes module:Table/useTableRowsVirtualization FR2, ORD3, PR1 and DEC-1 (four overscan rows per side) and adds an inline band that no record on main governs yet, so approval needs an engineering owner to update that spec and provide or identify the spec for the inline band, or to decline the band. An engineering owner, the author included, records the decision by commenting /approve-spec <full head SHA> on this pull request.
Blocking findings:
- While columns window, the new cell cache in
BaseTable.tsx(lines 373-414) reuses cells across a pin change, becauseuseTableStickyColumnskeeps one plugin object and reads its keys from a ref, so a newly pinned column's header sticks while its body cells scroll away (and an unpinned column's cells stay pinned); key the cache on the resolved pinned runs and add a pin and unpin regression test. - First-visible anchoring is still lost after a scroll shorter than half a band, because a data change anchors from the stale planned snapshot and the pending scroll write is then dropped (
useListWindow.tslines 233-262,useInlineListWindow.tslines 202-224), which contradicts FR8. - The description says anchoring is unchanged, that no correctness regressions were found and that content revisions pass the band at once, but the head regresses anchoring and pinned cells and now holds content revisions, so fix the defects or update those claims.
If the band is approved, the Chromium structural-bound specs also need to move to the new PR1 bound.
| const cellCache = useMemo( | ||
| () => ({ | ||
| // The inputs the cached cells were built from. | ||
| inputs: [ | ||
| item, | ||
| context, | ||
| plugins, | ||
| columns, | ||
| textOverflow, | ||
| rowHeight, | ||
| CellComponent, | ||
| ], | ||
| cells: new Map<TableColumn<T>, ReactElement>(), | ||
| }), | ||
| [item, context, plugins, columns, textOverflow, rowHeight, CellComponent], |
There was a problem hiding this comment.
These inputs miss plugin state that is read through a ref. useTableStickyColumns keeps one plugin object and reads its pinned keys from stateRef, so pinning or unpinning a column that stays mounted reuses the old cells: the header cell pins while its body cells keep scrolling, or an unpinned column's body cells keep their sticky inset. The base re-rendered every cell on the range change that follows a pin change. Key the cache on the pinned runs resolved at line 874 (or reuse cells only when the column range alone changed), drop the unused inputs field, and add a pin and unpin regression test.
70479a3 to
929ad50
Compare
Commits (each measurable on its own)
useSyncExternalStoreskips the render for an identical snapshot, so a scroll inside the band commits nothing, and a scroll on one axis never re-runs the other axis's plan.plan.start/plan.end), so it still runs in the layout effect of the commit that mounts them.min(512px, H), inlinemin(256px, W/2),Wbeing the width between the pinned runs.No velocity lead: it needs time-based state and its own commits, which is not cheap in a snapshot reader.
Deterministic tests
virtualization/scrollBand.test.tsx(fake shared geometry source, ReactProfiler, 2,000px of scrolling):ceil(2000/256)+1= 9ceil(2000/128)+1= 17useTableColumnsVirtualization.test.tsx, "renders only the cells of columns that enter the window" (Profiler plus per-column read counts, 20 rows): before commit 4, all 11 mounted columns rendered on a 300px scroll; after, only the 3 entering columns render, once per row.Full suite on commit 4:
vitest --project ui packages/core/src/virtualization packages/core/src/Table packages/core/src/utils110 files, 2046 tests pass;pnpm typecheckpasses; prettier and eslint clean on changed files.Measurements
Built Storybook, headless Chromium, one machine. Stories ran one at a time; variants in rotated order; medians of 5 runs; blank frames and cell renders from a separate pass. Cell renders count body cells whose props changed in a commit (a skipped cell keeps its props object). Stories: rows = 2,000 rows (320px viewport); columns = 300 columns, all 200 rows mounted; both = 10,000 × 302 (480px viewport). Patterns: (a) vertical 20px/frame × 300, (b) fast vertical 120px/frame × 150, (c) horizontal 20px/frame × 300, (d) diagonal 20/20 × 300, (e) jump to the middle and back × 10.
Variants: B0 stack top (no band) · B1 commit 1 (block
min(512,H), inlinemin(256,W/2)) · V1 B1 + commit 2 · V2 V1 with blockmin(256,H/2)· V3 V1 with blockmin(128,H/4)· V4 V2 with inlinemin(128,W/4)· C0 B0 + commit 4 · V6 V2 + commit 4. Patterns a and b only scroll vertically, so the column band and the cell fix (V4, C0, V6) were measured on c and d instead.Rows (2,000 rows)
Columns (300 columns, 200 rows mounted)
min(128,W/4))| c | 4× | B0 | 398 | 119,800 | 20779 | 650/717 | 300 | | | |
| c | 4× | C0 | 398 | 10,000 | 8809 | 400/500 | 300 | | | |
| c | 4× | V2 / V3 | 125 / 125 | 103,400 | 16938 / 17056 | 667/767 | 300 | | | |
| c | 4× | V4 | 174 | 153,000 | 24021 | 533/600 | 300 | | | |
| c | 4× | V6 | 125 | 9,800 | 6961 | 417/517 | 300 | | | |
Rows and columns (10,000 × 302)
A jump always leaves the very next frame uncovered, before the scroll reaches React, in every build.
Findings
min(128,W/4)(V4) raises commits, cell renders and script time on every column pattern.Recommended configuration
P = min(512px, viewport height), republish at P/2, holding content revisions.P = min(256px, half the width between the pinned runs), republish at P/2.These are the defaults on this branch, so no further default change was committed. The 10,000 × 302 diagonal and horizontal patterns with the 512px block band and the cell fix together were not measured as one build: the inline cost is the same as V6 there, and the block cost follows V1.
Contract wording this would change
Rows (
module:Table/useTableRowsVirtualization):min(512, viewport height)CSS pixels, plus at most one discontiguous focused product row. The island is never duplicated inside the window. Empty data mounts no data, spacer or island row."Vand bandP = min(512, V), mounted product rows are at mostceil((V + 2P)/rowHeight) + 1 + 1; the final one is the optional island. SSR rows are bounded by FR10's seed. There are at most three nonzero gaps; cells and element work scale with mounted rows and columns, never total data length."Columns (
module:Table/useTableColumnsVirtualization):min(256, half the unpinned viewport width)CSS pixels, plus at most one discontiguous focused column. With no unpinned column, column windowing changes nothing."W, bandP = min(256, W/2)and the narrowest windowed column widthw, mounted windowed columns are at mostceil((W + 2P)/w) + 1 + 1; the last is the optional focused column. Cells scale with mounted rows times mounted columns, never with the total column count."FR6 and FR10 (the seeds) do not change.
Correctness
No regressions found. Focus retention, anchoring, header/body alignment, full-table positions and coverage hold in the unit suite and in the column, focus and rows-plus-columns Chromium specs. Six existing Chromium assertions of the old structural row bound fail by design with any band larger than four rows (listed in the first iteration). The only new blank frames come from the rejected
min(128, H/4)block band at 120px per frame.Testing
scrollBand.test.tsxcases before and after commit 2vitest run --project ui packages/core/src/virtualization packages/core/src/Table packages/core/src/utilson commit 4(cd packages/core && pnpm typecheck)--checkand eslint--max-warnings=0on changed filesnode scripts/bench/table-scroll-band.mjswith 8 builds, stories one at a time, 5 runs, 1× and 4×Scope
Components: Table windowing (shared module), prototype only.