Skip to content

refactor(core): one shared list-windowing engine, with Table as its first consumer - #10810

Merged
cixzhang merged 5 commits into
mainfrom
refactor/shared-virtualization-engine
Nov 10, 2026
Merged

cixzhang merged 5 commits into
mainfrom
refactor/shared-virtualization-engine

Conversation

@cixzhang

@cixzhang cixzhang commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Maintainer impact

Table's row virtualization now runs on one shared list-windowing engine in Core, so Selector and Lab's ChatVirtualizer can reuse it instead of growing their own. This is an internal refactor: Table's behavior and public API do not change.

What moves

  • packages/core/src/utils/listWindow.ts (and its tests) → packages/core/src/virtualization/listWindow.ts. Unchanged: fixed-pitch range, gap segments and first-visible-key reconciliation.
  • New packages/core/src/virtualization/useListWindow.ts: the generic parts of Table's window controller, lifted from useTableWindow.ts without behavior change:
    • the shared geometry subscription;
    • first-visible-key anchoring across data and pitch changes (offset scaling, trailing content extent, the pending-anchor scroll);
    • the one retained focus island, with focus return to the viewport when the focused item unmounts;
    • the modality tracking that focus return reads.
  • New packages/core/src/virtualization/measure.ts: the canvas text metrics and pixel parsing helpers.
  • Table/plugins/virtualization/useTableWindow.ts keeps only Table's parts: capability-to-pitch admission, the rejection state and its warning, logical-position (row-number) column widths, and the mounted-row geometry diagnostics. It calls useListWindow.
  • The geometry snapshot's bodyOffset is renamed startOffset (internal; tableRuntime.ts).
  • Lab reaches the engine only through Core's private entry @astryxdesign/core/internal/virtualization (named re-exports; the same pattern as internal/scroll-anchoring). The @astryx/no-core-internal-import rule allows it only in Core and Lab. It has no root export, no docs and no index.ts, so it is not a public subpath.

Co-authored with Humberto Virtudes, whose window controller and list-windowing module this lifts unchanged.

Records

  • architecture:list-windowing names packages/core/src/virtualization/ and @astryxdesign/core/internal/virtualization as the shared module and routes both paths.

  • architecture:list-windowing owns the engine's home (its records PR adds the engine-home FR).

  • This PR points module:Table/useTableRowsVirtualization's shared claims at it: the range, overscan, gaps, anchor math, focus-island retention, and offset and measurement helpers. Table keeps admission and wiring.

Evidence

  • Existing tests, unchanged in substance: packages/core/src/Table and packages/core/src/virtualization suites pass (42 files, 784 tests), including the 1k/100k identity-work and 100k pre-cell planning cases. Only the renamed geometry field changed in the Table window tests.
  • New engine tests (useListWindow.test.tsx), independent of Table: a 10k list mounts only the visible rows plus four per side; one focused row stays mounted after it scrolls out and is released on blur; inserting rows above keeps the first visible key and its fractional offset; a list that may not window renders every row and subscribes to nothing.
  • Other checks: core tsc --noEmit, eslint, check:changesets, check:knowledge and core-internal-entries pass. The generated API report has no engine symbol, so the public API is unchanged.
  • Before/after bake-off report (timing, per-frame correctness, smoothness) from the shared harness: to be added at this PR's exact head before it goes ready.

Size (min+gzip JS, esbuild, other modules external)

Part main this PR
Table adapter (Table/plugins/virtualization: useTableWindow + useTableRowsVirtualization) 3,105 B 2,216 B
Shared engine (virtualization/: listWindow + useListWindow + measure) 985 B (listWindow only) 2,194 B

The adapter is still above the 2 KB budget, by 168 B. The follow-up PR replaces the row-number width measurement with CSS and contains the remaining virtualization-only logic in the plugin.

Before/after harness report (head c518793; 9ffe3e6 changes only a baseline key and a record)

Engine-swap compare, CI run 42776381526: before = main f6d2c316, after = this head c518793e. Medians of 3 seeded runs per cell; before and after share one runner in every throttle × text cell.

Case CPU× p95 ms before → after dropped first load ms overlap/gap/misplaced (after) max pos err px jumps / drift px Verdict
APPEND 1 16.7 → 16.8 0 → 0 244 → 245 0/0/0 0 0 / 0 ✓
APPEND 4 16.7 → 16.8 1 → 3 1123 → 1156 0/0/0 0 0 / 0 ✓
C-drag-10k 1 16.7 → 16.7 0 → 0 249 → 245 0/0/0 0 0 / 0 ✓
C-drag-10k 4 16.8 → 16.8 0 → 0 1163 → 1105 0/0/0 0 0 / 0 ✓
C-fling-100k 1 16.7 → 16.7 0 → 0 341 → 338 0/0/0 0 0 / 0 ✓
C-fling-100k 4 50 → 50 503 → 496 1608 → 1620 0/0/0 0 0 / 0 ✓
C-fling-10k 1 16.8 → 16.7 0 → 0 288 → 251 0/0/0 0 0 / 0 ✓
C-fling-10k 4 16.7 → 16.8 5 → 4 1151 → 1135 0/0/0 0 0 / 0 ✓
C-insert-above 1 16.8 → 16.7 0 → 0 245 → 248 0/0/0 0 0 / 0 ✓
C-insert-above 4 16.8 → 16.7 1 → 1 1164 → 1207 0/0/0 0 0 / 0 ✓
C-jump-100k 1 16.8 → 16.8 0 → 0 339 → 340 0/0/0 0 0 / 0 ✓
C-jump-100k 4 16.8 → 16.8 7 → 6 1580 → 1640 0/0/0 0 0 / 0 ✓
C-wheel-10k 1 16.7 → 16.7 0 → 0 250 → 258 0/0/0 0 0 / 0 ✓
C-wheel-10k 4 16.7 → 16.7 0 → 0 1135 → 1131 0/0/0 0 0 / 0 ✓

Every row passes, all at 100% text. Each frame is checked for overlap or gaps between adjacent rows, each row within 1px of an unwindowed render of the same rows, viewport coverage, and no jump (>1px) of the anchored row without input. Dropped = frames over 25ms.

Scope

  • One refactor; no behavior, visual or public API change.
  • Public text contains no internal Meta context.

Writing rubric results

  • Present tense, describes the system: yes; the Table record states who computes the range, island and anchor.

  • No history, pull requests or research in the record: yes.

  • Owner routing: shared claims point to architecture:list-windowing; Table-only admission and wiring stay in module:Table/useTableRowsVirtualization.

  • One topic per sentence: yes.

  • architecture:list-windowing: present tense; it describes the module at packages/core/src/virtualization/, its private entry and its consumers, with no history or pull requests; applies_to routes both paths.

…irst consumer

Moves utils/listWindow.ts to packages/core/src/virtualization/ and lifts
the generic parts of Table's window controller into it:
useListWindow (geometry subscription, first-visible-key anchoring across
data and pitch changes, the pending-anchor scroll, the one retained focus
island and focus return) and the canvas measurement helpers. Table keeps
its admission, logical-position column widths and mounted-row
diagnostics, and calls the shared hook. The geometry snapshot's
bodyOffset is named startOffset. Lab reaches the module only through
Core's private @astryxdesign/core/internal/virtualization entry. No
behavior or public API change.

Co-authored-by: Humberto Virtudes <[email protected]>
@vercel

vercel Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 10, 2026 10:05am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 9, 2026
@astracat-bot

astracat-bot Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🔄 In progress (for maintainers only) Nov 10, 2026, 10:39 AM UTC

@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 9, 2026
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · f0434f2

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC Visual · A11y · RTL
TableBody 3.5 kB (0) · 3.3 kB CSS (0) — ✓ · ✓ · ✗
TableFooter 3.5 kB (0) · 3.3 kB CSS (0) — ✓ · ✓ · ✗
TableHeader 3.5 kB (0) · 3.3 kB CSS (0) — ✓ · ✓ · ✗
8 more components
Component Size LoC Visual · A11y · RTL
TableRow 7.0 kB (0) · 4.0 kB CSS (0) — ✓ · ✓ · ✗
lab/Comments 353.1 kB (+229 B) · 2.5 kB CSS (0) — — · — · —
lab/CommentThread 346.2 kB (+181 B) · 2.4 kB CSS (0) — — · — · —
Markdown 188.9 kB (+153 B) · 20.7 kB CSS (0) — — · — · —
Table 126.1 kB (+137 B) · 18.4 kB CSS (0) — ✓ · ✓ · —
TableCell 110.5 kB (0) · 17.9 kB CSS (0) — ✓ · ✓ · ✓
TableHeaderCell 110.1 kB (0) · 17.7 kB CSS (0) — ✓ · ✓ · ✓
TableSelectionToolbar 70.9 kB (0) · 13.2 kB CSS (0) — ✓ · ✓ · ✓

Package size: @astryxdesign/core 7.25 MB packed (+4.2 kB); no new dependencies.

API changes: none in this pull request

Committed API report behind this build: cli 29 rows, core 36 rows; run pnpm api:report.

Touched components checked; add ci:run-visual or ci:run-rtl to run the full suites.


Generated by PR Enrichment workflow | View full report

@astracat-bot astracat-bot Bot left a comment

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.

Approval waits on an engineering owner's decision about this pull request's spec edits; the code change itself has no blocking finding.

  • This pull request rewrites ORD3 and the ownership lines of the current module:Table/useTableRowsVirtualization record so that architecture:list-windowing owns the first-visible-key anchor math, the focus-island retention and the measurement helpers, but the current architecture:list-windowing record does not state those yet, so an engineering owner needs to approve or reject these edits by commenting /approve-spec 6750aba67655ef78b19211b9fefeb174f3c36bd5 (the author may do so as an engineering owner).

The shared useListWindow hook matches Table's previous window controller, and Table's behavior and public API are unchanged. architecture:list-windowing still says no windowing module exists and does not list packages/core/src/virtualization/, so landing #10809 with or before this keeps that record accurate. The Owns list also drops "anchor policy" while FR8 and DEC-4 keep that policy in the Table record.

[Automated review]

@astracat-bot astracat-bot Bot left a comment

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.

Approval waits on an engineering owner's decision about this pull request's record edits; the code change has no blocking finding.

  • The edits to module:Table/useTableRowsVirtualization (the new ORD3 sentence, the Owns and Does-not-own lines, and the Range and Focus island owners) assign the first-visible-key anchor math, focus-island retention and the measurement helpers to architecture:list-windowing, which does not state those today, so an engineering owner approves them by commenting /approve-spec be02658701485b7e26848f42ac63af304c2120c5 (the author may do so as an engineering owner), or the edits are reworded to what that record states, for example keeping FR8's anchor policy under this record's Owns.

The shared useListWindow hook carries Table's previous window controller unchanged, so Table's behavior and public API stay the same, and the Table and virtualization suites pass at this head. architecture:list-windowing still says no windowing module exists and its applies_to does not cover packages/core/src/virtualization/, so the records update should fix both with or before this change.

[Automated review]

Main renamed the hook's viewportHeight to initialViewportHeight (#10894).
The Table adapter keeps the shared engine and maps the first-frame height
into the engine's pitch; the module record keeps main's Geometry row and
this branch's list-windowing owners.

@astracat-bot astracat-bot Bot left a comment

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.

Approval waits on an engineering owner's decision about this pull request's record edits; the code change has no blocking finding.

  • The edits to module:Table/useTableRowsVirtualization (the new ORD3 sentence, the Owns and Does-not-own lines, and the Range and Focus island owners) assign the first-visible-key anchor math, focus-island retention and the measurement helpers to architecture:list-windowing, which does not state those today, so an engineering owner approves them by commenting /approve-spec c518793e0e01a84670f6015ba0fcfa18b838a1b0 (the author may do so as an engineering owner), or the edits are reworded to what that record states, for example keeping FR8's anchor policy under this record's Owns.

The shared useListWindow hook carries Table's previous window controller unchanged, now fed from initialViewportHeight, so Table's behavior and public API stay the same; the Table and virtualization suites pass at this head. architecture:list-windowing still says no windowing module exists and does not route packages/core/src/virtualization/, so the records update should fix both with or before this change. A smaller suggestion: naming the engine's first-window field initialViewportHeight would make the comment in useTableWindow.ts unnecessary.

[Automated review]

}: UseTableWindowOptions<T>): TableWindowResult {
const [violation, setViolation] = useState<Violation | undefined>();
const config = getTableVirtualizationConfig(capability);
// The engine plans its first window from the declared first-frame height.

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 comment is needed only because the engine names the first-window height viewportHeight in ListWindowPitch, the same word as the measured height in ListWindowGeometry. Naming the engine field initialViewportHeight, as Table's public input is now named, lets the mapping explain itself, and the comment can go.

@cixzhang cixzhang added ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) ci:run-a11y Run the accessibility suite on this PR; write access, next push (AST-030 FR12) labels Nov 10, 2026
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec c518793

@astracat-bot astracat-bot Bot left a comment

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.

Changes requested: one repository test fails at this head. The record edits are now approved, and the refactor itself keeps Table's behavior and public API unchanged.

  • Miss: scripts/shared-identity.test.mjs fails because the canvas cache textContext moved to packages/core/src/virtualization/measure.ts while scripts/shared-identity.baseline.json still lists it as packages/core/src/Table/plugins/virtualization/useTableWindow.ts:textContext; rename that key to packages/core/src/virtualization/measure.ts:textContext and keep its allowed memo-cache reason.

The test passes on the base, and the Table and virtualization suites pass at this head. architecture:list-windowing still says no windowing module exists and does not route packages/core/src/virtualization/, so the records update should fix that. A smaller suggestion stands: naming the engine's first-window field initialViewportHeight would make the comment in useTableWindow.ts unnecessary.

[Automated review]

@cixzhang
cixzhang marked this pull request as ready for review November 10, 2026 08:47
…e the shared module

The canvas cache textContext moved with the text measurement into
packages/core/src/virtualization/measure.ts, so the shared-identity baseline
key follows it with its memo-cache reason. architecture:list-windowing now
routes packages/core/src/virtualization/ and its private entry, names them
as the module, and says Table uses it while Selector and Chat render every
item. No source change.
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 9ffe3e6

@astracat-bot astracat-bot Bot left a comment •

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.

Approved. The refactor keeps Table's behavior and public API unchanged, both record edits carry an engineering owner's approval for this head, and the full CI run at this head passes.

Non-blocking:

  • docs/architecture/list-windowing.md:32 and :82 describe which lists adopt the module next; a record states what the system is, so consider dropping "until they adopt it; then every windowed list behaves the same way".
  • The comment at useTableWindow.ts:268 explains only a field name; naming ListWindowPitch.viewportHeight initialViewportHeight makes it unnecessary.

[Automated review]

| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Governing contract | None. Each consumer's record owns what a person sees and hears in its long list; this record owns only which module computes the window. |
| System behavior | One shared internal windowing module owns long-list windowing in Core. The module is not public API (INV1, INV2). |
| End-user impact | A long Table windows through the module. Selector renders every option and Chat renders every message until they adopt it; then every windowed list behaves the same way. |

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: "until they adopt it; then every windowed list behaves the same way" states who adopts the module next, which is temporary project status. A record states what the system is; consider dropping that clause and keeping what INV1 requires. The same applies to "Selector renders every option when it opens, and Chat renders every message" in Current-state impact (line 82), which names no claim it is a gap against.

@cixzhang
cixzhang marked this pull request as draft November 10, 2026 09:16
@cixzhang
cixzhang marked this pull request as ready for review November 10, 2026 09:16
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec f0434f2

@astracat-bot astracat-bot Bot left a comment

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.

Approved pending CI: the deferred build and test lanes have not run on this head yet.

Table's row windowing now runs on the shared useListWindow hook with its behavior and public API unchanged. The built API surfaces match the base, both record edits carry an engineering owner's approval for this head, and Table's real-browser virtualization tests, which this merge brings in from main, pass on the shared hook.

Two optional follow-ups stay open on their earlier threads: drop the adoption sequencing in docs/architecture/list-windowing.md (lines 32 and 82), and name the engine's first-window height initialViewportHeight so the comment at useTableWindow.ts:268 can go.

[Automated review]

@cixzhang
cixzhang marked this pull request as draft November 10, 2026 10:30
@cixzhang
cixzhang marked this pull request as ready for review November 10, 2026 10:30
@cixzhang
cixzhang merged commit 1ac0c24 into main Nov 10, 2026
131 of 135 checks passed
cixzhang added a commit that referenced this pull request Nov 10, 2026
(A) merged as #10810. Main's Table files equal (A)'s, so this branch's
plugin split is kept; tableRuntime keeps its optional geometry driver.
@github-actions
github-actions Bot deleted the refactor/shared-virtualization-engine branch November 11, 2026 06:05

This branch was successfully deployed

1 active deployment
Preview — f0434f22 Deployed Nov 10, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) ci:run-a11y Run the accessibility suite on this PR; write access, next push (AST-030 FR12) CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant