fix(virtual-core): stop iOS deferred scroll adjustments from replaying stale deltas #1235
main fromrefs/pull/1235/head·merged by piecyk Summary#
Fixes both manifestations of #1233. On iOS WebKit the end-anchored virtualizer defers scroll compensation while it considers the scroller live, accumulating deltas in _iosDeferredAdjustment and replaying them in _flushIosDeferredIfReady() once things settle. Both bugs are the deferral replaying a delta whose premise no longer holds by flush time.
Fix 1 — absolute scroll commands invalidate the pending deferral#
scrollToOffset / scrollToIndex (and therefore scrollToEnd) compute their target from current measurements, so any deferred delta pending at that moment is stale — the command already accounts for the measurements the delta was compensating for. Previously the delta survived the command and replayed on the next flush (~150 ms later, at isScrollingResetDelay), shifting the list off the just-established position.
Reported symptom: programmatically restoring a saved reading position (repeated scrollToOffset while rows measure in) lands pixel-correct, then the flush fires and shifts the list a constant +74 px.
Fix: drop the deferral as the first statement of both absolute commands. Relative commands (scrollBy) keep it, since they build on the current offset. Off-iOS this is a no-op — the field is always 0 there.
Fix 2 — the flush drops a negative delta the browser's end clamp already absorbed#
With anchorTo: 'end' and the reader pinned at the bottom, a row above the viewport re-measuring smaller during isScrolling shrinks maxScrollOffset; the browser clamps scrollTop onto the new bottom, which is already the correct end-anchored position. The library had separately deferred a negative compensation for that same shrink, and the flush replayed it on top of the clamped position, lifting the view off the bottom by the net delta.
Reported symptom: a single room-open accumulated twelve deltas summing to −101 while the list settled at the bottom; the flush then wrote scrollTop 3543 → 3442, 101 px above the bottom.
Fix: the flush recognizes the end clamp (cur >= max - 1) and drops the stale negative delta. Positive deltas still replay — content growth above the viewport does not clamp (the browser can't shrink to fit growth) and the consumer's DOM sizer may not have grown yet, so a positive delta is still needed.
Testing#
iOS deferral: an absolute scroll command invalidates a pending deferred adjustment(Fix 1, both commands).iOS deferral: a negative delta at the end clamp is dropped, not replayed(Fix 2).iOS deferral: a positive delta at the end clamp still replays (growth above does not clamp)(guards against over-correcting Fix 2).- Full
virtual-coresuite passes (122/122); typecheck and eslint clean.
Both fixes are device-verified by the reporter (@stevan-borus) in production — the constant +74 px restore drift and the −101 px bottom jump are both gone.
🤖 Generated with Claude Code
Summary by CodeRabbit#
Bug Fixes
- Prevented stale iOS scroll adjustments from replaying after users issue absolute scroll commands.
- Improved end-anchored scrolling near the bottom of a list by avoiding compensations that could move the view away from the correct position.
- Preserved valid positive adjustments during end-anchored scrolling.
Documentation
- Clarified iOS deferred-scrolling behavior for absolute and relative scroll commands.
- 1
View your CI Pipeline Execution ↗ for commit 4457f3dba1ddff9dd20e324c71fbb3d1eff2620e
Command Status Duration Result nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded 2m 40s View ↗ nx run-many --target=build --exclude=examples/**✅ Succeeded 20s View ↗
☁️ Nx Cloud last updated this comment at
2026-07-20 08:20:43UTCMore templates
- @tanstack/virtual-example-angular-dynamic
- @tanstack/virtual-example-angular-fixed
- @tanstack/virtual-example-angular-infinite-scroll
- @tanstack/virtual-example-angular-padding
- @tanstack/virtual-example-angular-smooth-scroll
- @tanstack/virtual-example-angular-sticky
- @tanstack/virtual-example-angular-table
- @tanstack/virtual-example-angular-variable
- @tanstack/virtual-example-angular-window
- tanstack-lit-virtual-example-dynamic
- tanstack-lit-virtual-example-fixed
- tanstack-marko-virtual-example-dynamic
- tanstack-marko-virtual-example-fixed
- tanstack-marko-virtual-example-grid
- tanstack-marko-virtual-example-infinite-scroll
- tanstack-marko-virtual-example-smooth-scroll
- tanstack-marko-virtual-example-variable
- tanstack-marko-virtual-example-window
- tanstack-react-virtual-example-chat
- tanstack-react-virtual-example-dynamic
- tanstack-react-virtual-example-fixed
- tanstack-react-virtual-example-infinite-scroll
- tanstack-react-virtual-example-padding
- tanstack-react-virtual-example-pretext
- tanstack-react-virtual-example-scroll-padding
- tanstack-react-virtual-example-smooth-scroll
- tanstack-react-virtual-example-sticky
- tanstack-react-virtual-example-table
- tanstack-react-virtual-example-variable
- tanstack-react-virtual-example-window
- tanstack-vue-virtual-example-dynamic
- tanstack-vue-virtual-example-fixed
- tanstack-vue-virtual-example-infinite-scroll
- tanstack-vue-virtual-example-padding
- tanstack-vue-virtual-example-scroll-padding
- tanstack-vue-virtual-example-smooth-scroll
- tanstack-vue-virtual-example-sticky
- tanstack-vue-virtual-example-table
- tanstack-vue-virtual-example-variable
- tanstack-svelte-virtual-example-dynamic
- tanstack-svelte-virtual-example-fixed
- tanstack-svelte-virtual-example-infinite-scroll
- tanstack-svelte-virtual-example-smooth-scroll
- tanstack-svelte-virtual-example-sticky
- tanstack-svelte-virtual-example-table
@tanstack/angular-virtual
npm i https://pkg.pr.new/@tanstack/angular-virtual@1235@tanstack/lit-virtual
npm i https://pkg.pr.new/@tanstack/lit-virtual@1235@tanstack/marko-virtual
npm i https://pkg.pr.new/@tanstack/marko-virtual@1235@tanstack/react-virtual
npm i https://pkg.pr.new/@tanstack/react-virtual@1235@tanstack/solid-virtual
npm i https://pkg.pr.new/@tanstack/solid-virtual@1235@tanstack/svelte-virtual
npm i https://pkg.pr.new/@tanstack/svelte-virtual@1235@tanstack/virtual-core
npm i https://pkg.pr.new/@tanstack/virtual-core@1235@tanstack/vue-virtual
npm i https://pkg.pr.new/@tanstack/vue-virtual@1235commit:
9ce8a1fpiecyk changed the title
piecyk changed the title
piecyk merged this7dcfc07
piecyk closed this
Sign in to join this conversation.
📝 Walkthrough
Walkthrough#
Changes#
iOS scroll deferral handling
packages/virtual-core/src/index.tspackages/virtual-core/tests/index.test.ts,.changeset/ios-deferral-stale-replay.mdEstimated code review effort: 2 (Simple) | ~10 minutes
Possibly related issues
Possibly related PRs
_iosDeferredAdjustmentstate inpackages/virtual-core/src/index.ts.Suggested reviewers:
2wheeh,tannerlinsley🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 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.
❤️ Share