fix(react-virtual): grow size container before scroll sync on end-anchored prepend#1237
Merged
piecyk merged 2 commits intoJul 20, 2026
Merged
Conversation
…hored prepend In directDomUpdates mode the size container's height was written by the applyDirectStyles layout effect, which runs *after* the _willUpdate effect syncs the scroll position. On an end-anchored prepend, _willUpdate writes scrollTop to the new bottom while the container is still at its old, shorter height, so the browser clamps the write to the stale scrollHeight and the list is left with a gap at the top until the next scroll. Grow the container to the new total size before _willUpdate runs. React-rendered sizers are unaffected — they receive their height during render. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
View your CI Pipeline Execution ↗ for commit b8c2cb3
☁️ Nx Cloud last updated this comment at |
📝 WalkthroughWalkthroughThe direct DOM update path now applies the virtualization container’s total size separately and before item positioning or ChangesDirect DOM scroll synchronization
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a whitespace gap at the top of the list after an end-anchored prepend (e.g. "load older messages" in a chat pinned to the bottom) when using
directDomUpdatesmode.Root cause
On a prepend,
setOptionsgrows the total size and bumpsscrollOffsetto the new bottom in the same render pass. The scroll position is then synced in the_willUpdatelayout effect — but the size container's height is written by the separateapplyDirectStyleslayout effect that runs after it. So_willUpdatewritesscrollTopto the new bottom while the container is still at its old, shorter height, and the browser clamps the write to the stalescrollHeight. The list is left with a gap at the top until the next scroll re-reconciles.It only bites when at-end (that's the only time the new scroll target exceeds the stale
scrollHeight), and only indirectDomUpdatesmode — React-rendered sizers receive their height during render, so they're already tall by the layout-effect phase.Fix
Grow the size container to the new total before
_willUpdatesyncs the scroll position. Item positions are still written afterwards byapplyDirectStyles. The size write is extracted into a smallapplyContainerSizehelper (idempotent, guarded bylastSize) reused by both call sites.Testing
@tanstack/react-virtual: 7/7 pass;tsc --noEmitclean.🤖 Generated with Claude Code
Summary by CodeRabbit