Description#
When an element is temporarily hidden (e.g., display:none on the container), the ResizeObserver fires with size 0. This overwrites the valid cached measurement in resizeItem, causing calculateRangeImpl to include all items in the visible range (since all items now have end === 0), which results in a browser freeze or Maximum update depth exceeded error.
Fix#
Guard resizeItem against accepting a 0-size measurement when the item already has a previously cached size. First-time measurements of genuinely 0-height items remain accepted (no prior cache entry).
Tests#
- Verify 0-size is rejected when previous non-zero measurement exists in cache
- Verify first-time 0-size measurement is accepted (no prior cache)
- Verify 0-size → non-zero → 0-size cycle: non-zero measured after first 0 accepted, then 0 rejected after non-zero cached
Fixes #1188
Summary by CodeRabbit#
- Bug Fixes
- Prevented temporary zero-size measurements from overwriting previously cached item sizes.
- Reduced unnecessary re-renders and avoided infinite render loops when virtualized elements are temporarily hidden.
- Improved range calculations when items briefly report zero dimensions.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID:
0bf9fa20-beb1-4841-a43e-4b6fc350334a📥 Commits
Reviewing files that changed from the base of the PR and between d49cc526fe248be7b5ad97ec6ac814db8271b0d0 and 0846ad95b14a51eaa53faf2f0555738103883fe3.
📒 Files selected for processing (3)
.changeset/zero-size-reject-measurement.mdpackages/virtual-core/src/index.tspackages/virtual-core/tests/index.test.ts📝 Walkthrough
Walkthrough#
Virtualizer.resizeItemnow ignores zero-size measurements when an item already has a cached size. Tests cover cache update behavior, and a Changesets entry records a patch release for@tanstack/virtual-core.Changes#
Resize measurement handling
packages/virtual-core/src/index.ts,packages/virtual-core/tests/index.test.ts,.changeset/zero-size-reject-measurement.mdresizeItempreserves existing cached sizes for zero measurements, while tests verify initial zero measurements and later non-zero updates remain valid. A patch Changesets entry documents the fix.Estimated code review effort: 2 (Simple) | ~10 minutes
Possibly related PRs
Suggested reviewers:
piecyk🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
#1188by preventing zero-size measurements from overwriting cached sizes and causing crashes or slow loads.✨ Finishing Touches
🧪 Generate unit tests (beta)
Warning
There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.
🔧 ESLint
packages/virtual-core/tests/index.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/index.test.tsThanks 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