fix(virtual-core): stop viewport-spanning item growth from drifting scroll#1236
Conversation
…croll The default scroll-adjustment heuristic compensated any item whose top sat above the fold (`itemStart < scrollOffset`) on every re-measure. A streaming chat message that spans the fold (top scrolled above it, bottom below) grows at its bottom — below the anchor point — so compensating dragged scrollTop downward token by token, drifting the viewport (TanStack#1218). Re-measurements now only compensate items that are entirely above the fold (`itemStart + itemSize <= scrollOffset`); growth below the anchor point leaves the scroll position untouched. First measurements (estimate→actual) still compensate any above-fold item, and a custom shouldAdjustScrollPositionOnItemSizeChange still overrides the default. Fixes TanStack#1218. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe default resize compensation now skips adjustments when a re-measured item spans the viewport fold, while retaining compensation for fully above-fold items and first measurements. Regression tests cover these cases, and a patch changeset documents the behavior. ChangesScroll adjustment behavior
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related issues
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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
ESLint install timed out. The project may have too many dependencies for the sandbox. 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. Comment |
|
View your CI Pipeline Execution ↗ for commit 4f5ccc1
☁️ Nx Cloud last updated this comment at |
Summary
Fixes #1218.
When a streaming chat message that spans the fold (top scrolled above the viewport, bottom still below it) keeps growing at its bottom, the viewport drifts downward on its own —
scrollTopcreeps up token by token while the distance to the bottom stays constant.Root cause
The default scroll-adjustment heuristic in
resizeItemcompensated a size change for any item whose top sat above the fold:That condition can't distinguish an item that is entirely above the fold from one that merely spans it. A streaming message grows at its bottom — i.e. below the anchor point — so compensating by the full delta shifts
scrollTopand drags the viewport.Fix
Split the two cases in the default predicate:
itemStart + itemSize <= scrollOffset. Growth below the anchor point now leaves the scroll position untouched.shouldAdjustScrollPositionOnItemSizeChangestill overrides the default.Testing
@tanstack/virtual-core: 125/125 pass, including 3 new regression tests covering: spanning-item growth (no drift), entirely-above growth (still anchors), and first-measurement compensation.@tanstack/react-virtual: 7/7 pass.tsc --noEmitclean.🤖 Generated with Claude Code
Summary by CodeRabbit