Skip to content

fix(VirtualGrid): backport 1.7.3 initial-setup fixes to 1.6 - #102

Merged
chiefcll merged 1 commit into
1.6from
backport/virtualgrid-1.6
Dec 1, 2026
Merged

chiefcll merged 1 commit into
1.6from
backport/virtualgrid-1.6

Conversation

@chiefcll

@chiefcll chiefcll commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Backports the VirtualGrid fixes that reached 1.7 through #72 (B15) to the 1.6 line. 1.6.9 already has the row-animation fix (#86); this adds the rest. src/primitives/VirtualGrid.tsx is now byte-identical to its 1.7.3 version.

Ported (VirtualGrid only)

  • An initial selected scrolls to its row and is applied once (initialSelectedPending, forceRowScroll, applySelected). For that call the app's onSelectedChanged gets lastIdx === idx, as Row and Column report a mount selection.
  • The node's selected is now a child index into the window (max(0, props.selected - start()), set once with @once), not the data index. Before, autofocus with selected={10} focused item 16. Also, setting a reactive selected back to the first row left the grid scrolled 60px up.
  • Last-row guard: maxRows = floor((count - 1) / perRow). The old guard was one row late when the count is a multiple of columns.
  • this.selected is written only when a child exists at the new index. Before, a Down with nothing below lost the next Up.
  • One flex pass per window shift: a layoutPending flag, cleared by an onLayout wrapper that still calls the app's onLayout, and applyShift with no closure per press.
  • cursor is set in its own createRenderEffect instead of in the props spread, so a press no longer re-reads every spread prop.

Dependencies

None. 1.6 already has lngp.chainRefs and node onLayout support, and its onLayout call semantics in updateLayout match 1.7.3. The 1.7.3 changes in withScrolling.ts (renderer-v2 local caching) and handleNavigation.ts (B1 wrap fix) are not needed by VirtualGrid, so they are not ported.

Deliberately left out

Renderer 2.0 changes, TS7/oxlint tooling, and Virtual/Row/Column/Grid changes. Virtual.tsx is untouched.

Tests

tests/contract-virtual-grid.test.tsx now matches its 1.7.3 version: 3 BUG: skips are un-skipped as B15 tests, 2 lastIdx expectations are updated, and 8 tests are added (layout-pass count, cursor-spread probe, initial selected without autofocus, items arriving after mount ×2, past the end, mount lastIdx ×2).

  • With 1.6.9's VirtualGrid source, 7 of these tests fail. With the port, all 17 pass.
  • pnpm run build: passes.
  • pnpm test: 36 files, 702 passed, 20 skipped, 1 todo. Baseline on origin/1.6 was 691 passed, 23 skipped, 1 todo.
  • pnpm run lint: 0 errors, 157 warnings, the same as the baseline.

🤖 Generated with Claude Code

Brings src/primitives/VirtualGrid.tsx to its 1.7.3 state (B15 fixes from
#72) and ports the matching contract tests:

- an initial `selected` scrolls to its row and is applied once; the app's
  onSelectedChanged sees lastIdx === idx for that call, as with Row/Column
- the node's `selected` is a child index into the window, set once, not
  the data index (autofocus with selected past the first window focused
  the wrong item; reactive selected back to row 0 left the grid scrolled)
- last-row guard uses floor((count - 1) / perRow)
- `this.selected` is written only when a child exists at the new index
  (a Down with nothing below lost the next Up)
- one flex pass per window shift (layoutPending + onLayout wrapper,
  applyShift without a per-press closure)
- `cursor` set in its own render effect instead of the props spread

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chiefcll
chiefcll merged commit caa3c0e into 1.6 Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant