Uh oh!
There was an error while loading. Please reload this page.
fix(react-virtual): grow size container before scroll sync on end-anchored prepend - #1237
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 |
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