Skip to content

fix(virtual-core): invalidate measurements when gap option changes#1223

Merged
piecyk merged 5 commits into
TanStack:mainfrom
2wheeh:fix/reactive-gap
Jul 12, 2026
Merged

fix(virtual-core): invalidate measurements when gap option changes#1223
piecyk merged 5 commits into
TanStack:mainfrom
2wheeh:fix/reactive-gap

Conversation

@2wheeh

@2wheeh 2wheeh commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

🎯 Changes

resolves #1222

gap was missing from the getMeasurementOptions memo dependencies, so a gap-only option change never invalidated cached measurements.

The list kept the layout computed with the old gap until something else (count change, item resize, remount) recomputed it.

Changes

  • Add options.gap to the measurement memo key and thread it through to getMeasurements, replacing the direct this.options.gap reads
  • Regression tests: virtual-core (single-lane and multi-lane) and react-virtual (gap change via rerender)

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.

Summary by CodeRabbit

  • New Features
    • Added/recognized an optional spacing gap prop for virtualized lists, so item/row positioning reflects updated gap values.
  • Bug Fixes
    • Virtualized measurements now correctly refresh when gap changes, preventing stale cached positions.
    • Total size and lane/row start calculations stay accurate after gap updates.
  • Tests
    • Added regression coverage for both single-lane and multi-lane gap changes.
  • Chores
    • Added a patch release note calling out that gap changes invalidate measurements.

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 30a16b98-f4a4-4731-bffb-b2f2b6494023

📥 Commits

Reviewing files that changed from the base of the PR and between b816cf9 and 1b32928.

📒 Files selected for processing (1)
  • packages/virtual-core/src/index.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/virtual-core/src/index.ts

📝 Walkthrough

Walkthrough

Fixes stale virtualizer measurements when gap changes dynamically. Measurement memoization now tracks gap, layout calculations use the updated value, and regression tests cover single-lane, multi-lane, and React rendering behavior. A changeset records a patch release for @tanstack/virtual-core.

Changes

Gap Invalidation Fix

Layer / File(s) Summary
Memoize gap in measurement options and layout calculations
packages/virtual-core/src/index.ts
getMeasurementOptions tracks and returns gap; getMeasurements uses it for single-lane and multi-lane start-offset calculations.
Regression tests, React wiring, and release note
packages/virtual-core/tests/index.test.ts, packages/react-virtual/tests/index.test.tsx, .changeset/eighty-ants-slide.md
Tests verify recomputed starts, total size, and rendered transforms after gap changes; the changeset declares a patch release for @tanstack/virtual-core.

Estimated code review effort: 2 (Simple) | ~12 minutes

Possibly related PRs

  • TanStack/virtual#1224: Both changes modify virtual-core multi-lane placement logic, including lane start calculations.

Suggested reviewers: piecyk

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately describes the main change: invalidating measurements when gap changes.
Description check ✅ Passed The description covers the bug, fix, regression tests, checklist, and release impact, matching the template well.
Linked Issues check ✅ Passed The code and tests address #1222 by invalidating cached measurements and updating layout/getTotalSize on dynamic gap changes.
Out of Scope Changes check ✅ Passed The changes are focused on the gap invalidation fix, related tests, and a changeset, with no obvious unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@2wheeh 2wheeh force-pushed the fix/reactive-gap branch from be55d6b to e9b1486 Compare July 7, 2026 11:28
@2wheeh 2wheeh changed the title Fix/reactive gap fix(virtual-core): invalidate measurements when gap option changes Jul 7, 2026
@2wheeh 2wheeh marked this pull request as ready for review July 7, 2026 11:30
@nx-cloud

nx-cloud Bot commented Jul 12, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 1b32928

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 2m 41s View ↗
nx run-many --target=build --exclude=examples/** ✅ Succeeded 20s View ↗

☁️ Nx Cloud last updated this comment at 2026-07-12 09:31:21 UTC

@pkg-pr-new

pkg-pr-new Bot commented Jul 12, 2026

Copy link
Copy Markdown
More templates

@tanstack/angular-virtual

npm i https://pkg.pr.new/@tanstack/angular-virtual@1223

@tanstack/lit-virtual

npm i https://pkg.pr.new/@tanstack/lit-virtual@1223

@tanstack/marko-virtual

npm i https://pkg.pr.new/@tanstack/marko-virtual@1223

@tanstack/react-virtual

npm i https://pkg.pr.new/@tanstack/react-virtual@1223

@tanstack/solid-virtual

npm i https://pkg.pr.new/@tanstack/solid-virtual@1223

@tanstack/svelte-virtual

npm i https://pkg.pr.new/@tanstack/svelte-virtual@1223

@tanstack/virtual-core

npm i https://pkg.pr.new/@tanstack/virtual-core@1223

@tanstack/vue-virtual

npm i https://pkg.pr.new/@tanstack/vue-virtual@1223

commit: 1b32928

@piecyk piecyk merged commit d49cc52 into TanStack:main Jul 12, 2026
10 checks passed
@2wheeh 2wheeh deleted the fix/reactive-gap branch July 12, 2026 09:38
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.

Changing the gap option dynamically does not invalidate cached measurements

2 participants