Skip to content

fix(virtual-core): rebuild cleared measurements before resizeItem after measure() - #1420

Open
dbsghdz1 wants to merge 1 commit into
TanStack:mainfrom
dbsghdz1:fix/measure-then-resize
Open

dbsghdz1 wants to merge 1 commit into
TanStack:mainfrom
dbsghdz1:fix/measure-then-resize

Conversation

@dbsghdz1

@dbsghdz1 dbsghdz1 commented Dec 1, 2026 •

Copy link
Copy Markdown

Fixes #1419

measure() clears itemSizeCache and bumps itemSizeCacheVersion, leaving the rebuild to the next read. resizeItem() only rebuilt first when the measurement options changed, so a call between measure() and the next read compared the new size with the old layout. Rows above it kept their old sizes (through pendingMin), and a size equal to the old one was dropped.

Now resizeItem() also rebuilds first when itemSizeCacheVersion moved by something other than its own pending resizes (builtItemSizeCacheVersion + pendingResizes.length, the same check canShiftFromPendingResizes uses). Back-to-back resizeItem() calls without measure() in between do not rebuild, as before.

Tests

  • measurement.test.ts: measure() then resizeItem(2, 888); row 0 goes back to its estimate (50) and row 2 starts at 100.
  • measurement.test.ts: measure() then resizeItem(0, 200) with the size row 0 had before; it stays 200.
  • Both fail on main and pass with this change. vitest run (545 passed), tsc, eslint ./src and prettier pass in packages/virtual-core.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected virtualized list sizing when an item is resized after measurements are reset. Updated sizes now appear in item positions and total list size, including when a resized item matches the size that was cleared. Items above the resized row no longer retain outdated measurements.

@changeset-bot

changeset-bot Bot commented Dec 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ff9a1fc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
@tanstack/virtual-core Patch
@tanstack/angular-virtual Patch
@tanstack/lit-virtual Patch
@tanstack/marko-virtual Patch
@tanstack/react-virtual Patch
@tanstack/solid-virtual Patch
@tanstack/svelte-virtual Patch
@tanstack/vue-virtual Patch
@tanstack/virtual-benchmarks Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

resizeItem() now rebuilds measurements when the item-size cache changes after measure(). Two regression tests cover subsequent resize calls and verify item sizes, positions, and total size.

Changes: Measurement reset and resize

Layer / File(s) Summary
Rebuild measurements after cache changes
packages/virtual-core/src/index.ts, packages/virtual-core/tests/measurement.test.ts, .changeset/measure-then-resize.md
resizeItem() now checks whether the item-size cache version differs from the built version plus pending resizes. Two tests cover resize calls after measure(). The changeset declares a patch for @tanstack/virtual-core.

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

Change: Bug fix

Possibly related PRs

  • TanStack/virtual#1381: It changes resetItemSize through a shared resizeItem path that also uses version invalidation and pending minimum handling.

Suggested reviewers: piecyk, rayw-lab

Merge Risk: Minimal · up to ff9a1

This patch makes resizeItem() work correctly when it is called after measure() and before the next layout read, so rows that were not re-measured use their estimates and every reported size is kept. The change is small and covered by regression tests, and no concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the fix in virtual-core: resizeItem() now rebuilds cleared measurements after measure(). This matches the changeset, the index.ts change, and the regression tests, so it is the main ch…
Description check Passed The description follows the template. It explains the change and its motivation, and it links issue #1419. It lists the two regression tests and the local checks that were run. The checklist items are…
Linked Issues check Passed Issue #1419 requires two behaviors after measure() clears itemSizeCache: (a) rows not measured again fall back to their estimate, and (b) a size reported through resizeItem() is kept even when it equa…
Out of Scope Changes check Passed The changed files are a changeset (.changeset/measure-then-resize.md, patch for @tanstack/virtual-core), the resizeItem change in packages/virtual-core/src/index.ts (+5/-1), and two regression tests i…
Full details: Title check

Explanation

The title names the fix in virtual-core: resizeItem() now rebuilds cleared measurements after measure(). This matches the changeset, the index.ts change, and the regression tests, so it is the main change.

Full details: Description check

Explanation

The description follows the template. It explains the change and its motivation, and it links issue #1419. It lists the two regression tests and the local checks that were run. The checklist items are not ticked, and the Release Impact section is not marked. The changeset file in the summary shows a changeset was added, so the release item is likely met, but the author did not tick it.

Resolution

Optionally tick the checklist items: the Contributing guide and pnpm run test:pr steps, and the Release Impact box for a published change with a changeset. The description is otherwise complete.

Full details: Linked Issues check

Explanation

Issue #1419 requires two behaviors after measure() clears itemSizeCache: (a) rows not measured again fall back to their estimate, and (b) a size reported through resizeItem() is kept even when it equals the row's former size. The PR adds a check in Virtualizer.resizeItem (packages/virtual-core/src/index.ts) that rebuilds measurements first when itemSizeCacheVersion differs from builtItemSizeCacheVersion + pendingResizes.length. This rebuild happens before the resize is compared, so the delta is computed against the cleared layout. The two regression tests in measurement.test.ts cover both behaviors: measure() then resizeItem(2, 888) expects row 0 to be 50 and row 2 to start at 100, and measure() then resizeItem(0, 200) with the prior size expects row 0 to stay 200. Back-to-back resizeItem() calls without measure() do not trigger the rebuild, which matches the issue's existing reverse-order coverage. Evidence limit: the diff hunk for resizeItem could not be read directly (the diff tool reported missing blobs). This verdict relies on the supplied summary and the PR description, which describe the same logic consistently.

Full details: Out of Scope Changes check

Explanation

The changed files are a changeset (.changeset/measure-then-resize.md, patch for @tanstack/virtual-core), the resizeItem change in packages/virtual-core/src/index.ts (+5/-1), and two regression tests in packages/virtual-core/tests/measurement.test.ts. Each change directly supports the fix for #1419. No unrelated behavior, public API, or exported declaration changes are reported. The direct diff could not be read, so this verdict relies on the supplied summary.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/virtual-core/tests/measurement.test.ts

Parsing error: "parserOptions.project" has been provided for @typescript-eslint/parser.
The file was not found in any of the provided project(s): packages/virtual-core/tests/measurement.test.ts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f05beafb-6c27-46bc-aeb1-9d887948182b
Commits

Reviewing files that changed from the base of the PR and between d4a079b and ff9a1fc.

Files selected for processing: 3

  • .changeset/measure-then-resize.md
  • packages/virtual-core/src/index.ts
  • packages/virtual-core/tests/measurement.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

This branch has not been deployed

No deployments
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.

resizeItem() right after measure() measures against the layout measure() cleared

1 participant