iOS scroll-correction deferral: per-row record, iOS 27 momentum, and index-scroll exits #1307
Plan for #1307#
The anchor proposal in the issue is dropped: it needs history under momentum and changes which resizes get compensated. This plan is built from the measurements in this thread (iOS 18.2, 26.5 and 27.0 simulators, iPhone on 27.0.1) and from the tests pinned in #1308.
What we know#
| Phase | iOS ≤ 26 | iOS 27+ |
|---|---|---|
| Finger down | a scrollTop write is ignored | a scrollTop write is ignored |
| Momentum | a write stops the momentum | the write lands and momentum continues |
- The deferral is needed under a finger on every version, and during momentum only on ≤ 26. On 27+ deferring during momentum just leaves the content shifted until the flush.
- Detecting 27+: the UA's OS token is frozen (
iPhone OS 18_7on 26 and 27; iPad reports a Mac).Version/is real in Safari but likely missing in in-app web views and Chrome/Firefox on iOS.CSS.supports('overflow-anchor: auto')is true only on 27 in the measured versions, doesn't read the UA, and is false (keep deferring) when absent. - One accumulated delta loses information the flush needs: a correction is replayed after the gesture has carried the viewport above the resized row (the reverse flick).
- Several bugs aren't iOS-specific: the stale
scrollOffsetbefore a write's read-back, and the pull-back of an index scroll that never reached its target.
Steps#
Each step is its own PR, fixes named test.fails from #1308 (removing .fails), and leaves the rest green. Each runs a full option sweep (align, lanes, padding, scrollPaddingStart, scrollMargin, horizontal, custom adjust predicate, anchorTo, prepend, iOS UA) before it is opened, test:pr, and the chat e2e suites repeatedly.
1. Stale scrollOffset before a write's read-back (all platforms): #1309#
While a scroll command's write hasn't been read back, resizes are left to reconcile instead of being compensated against the old offset; scrollBy builds on the written offset.
- Fixes: "scrollToIndex (#1307): a resize classified against the stale offset does not overwrite the index scroll".
- Adds
tests/ios-differential.test.ts(same event script on iOS and non-iOS, compares where they settle, flags a reconcile that needs the safety valve).
2. Pull-back of an index scroll that never landed (all platforms): #1310#
A scroll event that isn't the read-back of our own write ends the index scroll whether or not it reached its target (today only after hasReachedTarget). On iOS this also covers the finger-down case, where the write is ignored and the scroll can never land.
- Fixes: "a drag that never reached the target is not pulled back when the target moves", "a scroll away from a target that moved before landing is not pulled back, non-iOS".
- Watch: smooth scrolls produce intermediate scroll events that aren't our read-back, and a smooth retarget resets
hasReachedTargetfor that reason. They need their own rule, likely "a smooth scroll is interrupted only by an event moving away from the target".
2a. Refactor: the scroll state as an explicit phase (no behaviour change): #1311#
ScrollState described its lifecycle through flags: behavior (switched from 'smooth' to 'auto' by reconcile for the final approach, which also re-enables size compensation), hasReachedTarget, and since #1310 startedSmooth (WebKit delivers smooth-animation events after that switch). Their combinations encode four situations, so they become one phase:
smooth a smooth animation is travelling to the target
smoothLanded a smooth scroll is at its target, waiting to retire
smoothFinishing a smooth scroll switched to instant writes for the final
approach; its animation can still report positions
instant instant writes
Checks ask about the phase through two helpers: isSmoothScroll (compensation, anchor sync and far measurements hold off) and isAnimating (a scroll event that isn't our read-back may be the animation, not the user).
- Behaviour-preserving: identical traces against the parent on 3,000 random event sequences, plus the #1308 tests,
tests/ios-differential.test.ts, and the react-virtual smooth/scroll/cached-measurements e2e in Chromium, Firefox and WebKit. - Before step 4, which reworks the iOS deferral state anyway.
2b. Defer only for touch-driven scrolls (all iOS versions): next#
Today the deferral is gated on isScrolling, which any scroll event sets, including the read-back of our own programmatic write. So a scrollToOffset landing paints sagged until scrolling settles and then snaps (#1250). Since #1305 a scrollToIndex landing sags for one frame until reconcile retargets. A programmatic scroll has no momentum to protect; only a touch does.
- Gate the deferral (in
applyScrollAdjustment, the prepend anchor sync, and the flush) on touch provenance: a finger is down, or the momentum tail aftertouchend. While the tail is open, each scroll event re-arms its timer, so it spans the fling and closes itself after the last frame; a scroll event with no preceding touch never opens it. - An absolute scroll command closes the tail (its write stops momentum on ≤ 26 anyway);
touchcancelis handled liketouchend. - Regression tests carried over from #1280: a tap that doesn't scroll must not latch the deferral, and a landing issued from a tap handler compensates before paint.
- Fixes #1250. Gives step 3 a precise "momentum phase" to gate on instead of
isScrolling. - A prototype of the gate on top of #1311 makes all 12 known iOS/non-iOS divergences in
tests/ios-differential.test.tsconverge and fixes three #1308test.fails(cancelScroll, the safety valve,scrollByreplacing an index scroll). About 15 existing iOS tests model momentum as scroll events without touch events and need rewriting with explicittouchstart/touchend. - #1305's "drop corrections during an index scroll" branch only stays reachable while a finger is down, where #1310 already ends the index scroll on the finger's first scroll event. Remove it if the tests and the harness agree.
- Taken from #1280, which bundled this with the prepend fix in step 5 and is closed in favour of this plan.
3. iOS 27+: don't defer during momentum (small, may ride with 2b)#
Defer under a finger and in the post-touchend grace window as today; during momentum on 27+, write the correction immediately like every other platform.
- Gate:
isIOSWebKit() && CSS.supports('overflow-anchor: auto'), optionally confirmed byVersion/ >= 27. Absent or false keeps today's behaviour. - Check first, with the #1308 page on the 27 simulator and the device: whether Safari 27's native scroll anchoring adjusts anything itself for transform-positioned rows (it would double the correction), and whether the virtualizer should set
overflow-anchor: noneon the scroller. - Tests: jsdom with
CSS.supportsstubbed for both answers; the existing touch-phase tests must pass unchanged. - With 2b's explicit momentum tail this is one condition on that tail.
- Shrinks step 4: on 27+ only the finger-down phase still defers.
4. Per-row deferral record (conditional: decide after 2b and 3)#
After 2b and 3, what's left for this step is iOS ≤ 26 during real touch momentum and drags, chiefly the reverse flick. Decide with the #1308 device page whether it is worth the complexity or whether accepting that case on older iOS is the better trade.
Replace _iosDeferredAdjustment with a record of the deferred corrections per row (key → delta, using the same predicate as today), plus prepend shifts.
- At flush, apply only the corrections for rows that are still above the current viewport. That fixes the reverse flick and keeps momentum travel correct.
- During an index scroll keep recording instead of dropping (#1305). A reconcile retarget write absorbs everything recorded before it, so it clears the record. Exits that end the scroll without landing (gesture,
cancelScroll,scrollBy, safety valve) leave the record for the flush. - Fixes: "a correction is not replayed once the viewport is above the resized row", and the index-scroll exits: "a gesture before the index scroll retargets…", "cancelScroll before the index scroll retargets…", "the reconcile safety valve…", "scrollBy replacing an index scroll…".
- Keeps: the five behaviour tests from #1308 (momentum baseline, forward vs backward re-measure, custom predicate opting out, first measure of the row spanning the viewport top, non-iOS gesture).
- Test rework: 31 assertions on
mainread_iosDeferredAdjustment. The ones that pin what was deferred move to a small read-only accessor or to position assertions. Two #1308test.failshave an intermediate check (_iosDeferredAdjustment === 50, an intermediate 2550) that would keep them green for the wrong reason; drop those before relying on them. - The differential harness gets one documented exception: iOS skips corrections for rows that ended below the viewport, which non-iOS applied at resize time.
5. Shared stalls and prepend fixes (separate PRs)#
Found while reviewing steps 1 and 2, same on main:
scrollToOffset/scrollBy, then a row above grows after the read-back: the compensation moves off the fixed target and reconcile never rewrites it until the safety valve.- A prepend (
anchorTo: 'end') before the read-back of ascrollToIndex: the anchor sync writes from the stale offset and overrides the index scroll until the safety valve. - A deferred prepend correction is applied twice (from #1280):
setOptionsfolds the anchor delta into the trackedscrollOffseteagerly, and when the DOM sync is deferred under a finger, the flush writesscrollOffset + deferred. A fling to the top that lands on a prepend jumps by the prepend's height.
Related issues#
- #1250: fixed by step 2b (partly by #1305 already:
scrollToIndexsags for one frame instead of snapping later;scrollToOffsetstill snaps). - #884: the reason the deferral exists; addressed on
mainsince@tanstack/virtual-core3.15.0 (#1168). On iOS 27 a write no longer stops momentum at all (step 3). - #1287: out of scope. Desktop Safari discards a write made during the rubber-band bounce; no touch and no iOS deferral are involved, so it needs its own fix.
Verification on devices#
The #1308 page (react-virtual/e2e/app/ios-deferral) is the manual check for steps 2–4: the 18.2, 26.5 and 27.0 simulators and a 27 device, with real gestures, for the momentum baseline, the reverse flick, a resize under a finger, and scrollToIndex during momentum and under a finger. Not yet covered by anyone: in-app WKWebViews, Chrome/Firefox on iOS, and iOS versions between 26.5 and 27.0.
Open questions#
- Does Safari 27's native scroll anchoring touch transform-positioned rows? (Decides whether step 3 also needs
overflow-anchor: none.) - Does
CSS.supports('overflow-anchor: auto')hold in WKWebView and in Chrome/Firefox on iOS 27? - For step 2, should a user scroll during a smooth
scrollToIndexcancel it? Today it doesn't until the target is reached.
Thank you, this is exactly the evidence the issue was missing, and it changes the plan.
Momentum on iOS 27: with the 27.0 simulator matching the device, it's the OS version, not hardware. That splits the deferral in two: while a finger is down writes are ignored on every version, so that part stays; during momentum, iOS ≤26 needs the deferral but on 27+ it only delays the correction. I think the first step is to skip the momentum-phase deferral on 27+ and keep the touch-phase one everywhere, before redesigning anything. One open question: how to detect 27+ reliably, does the Safari UA on 27 still carry the real OS version, or is it frozen? If you can check
navigator.userAgenton the device and the simulators, that would settle it.Corrections: agreed on all four. I'll update the issue:
dropScrollStatewas #1306 only (closed), the stale-scrollOffsetbug is cross-platform and tracked separately, the pull-back has the finger-down cause you identified, and the acceptance criteria shouldn't reference tests that aren't onmainor assert_iosDeferredAdjustment.Stale
scrollOffset: I have a fix in progress as its own PR (compensate against the last written offset until its read-back, all platforms), with a differential iOS/non-iOS test harness. Your forced-measureElementrepro in real Safari is a great confirmation.Anchor vs per-row: agreed the anchor needs history and changes which resizes are compensated; we'd reached the same conclusion. Your reverse-flick case also convinced me that "same final offset as non-iOS" is the wrong target. A per-row record decided at flush time ("skip corrections for rows now below the viewport") is the better rule for the cases that still defer (touch everywhere, momentum on ≤26).
Your tests and instrumented page: yes please, a PR with them would be very useful, especially the e2e app entry, since we can't reproduce real momentum in jsdom.
One more data point on point 3 (the pull-back): it isn't limited to iOS writes being ignored under a finger. Any index scroll whose target keeps moving before reconcile sees it land stays
hasReachedTarget: false, so a user scroll never retires it, and the next measurement that moves the target writes the user back. Reproduced in jsdom againstmain(non-iOS):v.scrollToIndex(50, { align: 'start' }) // writes 2500 scroll(2500, true) // read-back v.resizeItem(10, 100) // target moves to 2550 before reconcile sees it land frame() // reconcile retargets to 2550, hasReachedTarget stays false scroll(2550, true) scroll(1000, true) // the user scrolls away: state still alive frame() // nothing happens yet (scrollTop 1000) v.resizeItem(5, 100) // any measurement that moves the target frame() // scrollTop 2600: pulled back to the targetI hit it in desktop Chromium through the Marko chat e2e while working on the stale-
scrollOffsetfix: extra size corrections during the initialscrollToEndkept the end target moving, so the pin never "landed", and scrolling up to read history got yanked back to the bottom on the next measurement.maindoesn't trigger it in that flow today, but the trap is there for any long index scroll whose rows keep getting measured. Treating a user scroll as an interruption whether or not the target was reached (with the read-back of our own writes excluded, as the scroll handler already does via_intendedScrollOffset) looks like the direct fix; I'll track it with the rest of this issue.User agent on 27: the OS token is frozen,
Version/is not. Safari, one load each:OS token in the UA Version/navigator.platformiPhone simulator 18.2 iPhone OS 18_218.2 iPhone iPhone simulator 26.5 iPhone OS 18_726.5 iPhone iPhone simulator 27.0 iPhone OS 18_727.0 iPhone iPhone 16 Pro, 27.0.1 iPhone OS 18_727.0.1 iPhone iPad simulator 18.2 Intel Mac OS X 10_15_718.2 MacIntel iPad simulator 26.5 Intel Mac OS X 10_15_726.5 MacIntel iPad simulator 27.0 Intel Mac OS X 10_15_727.0 MacIntel The device string in full:
Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/27.0.1 Mobile/15E148 Safari/604.1So
iPhone OS x_ycannot tell 26 from 27, and on iPad it never carried an iOS version./Version\/(\d+)/gives the real major on all seven.navigator.userAgentDatais absent on all of them.Not measured: in-app WKWebViews and Chrome/Firefox on iOS. As far as I remember their UAs have no
Version/token, which with the OS token frozen would leave nothing to read 27 from. That needs checking before relying on it either way.Given that, I'd skip the momentum-phase deferral only when
Version/parses to 27 or higher and keep deferring when it is missing. That is today's behaviour, and on 27 it costs a delayed correction rather than a wrong one.Pull-back on non-iOS: your repro gives the same result here against
main,scrollTop2600 where the resize of row 5 alone would give 1050. I added it as atest.failsnext to the finger-down one.PR: #1308 has the tests and the
ios-deferrale2e page. Two things to know before reading it: the page posts its log to/log, which nothing in the repo serves (I used a small local server), andchat.spec.ts:73times out in the full e2e run on my machine, onmainas well in 1 of 3 runs. Details are in the PR description.A suggestion for the 27+ detection that avoids the UA:
CSS.supports('overflow-anchor: auto’)(see https://blog.openreplay.com/ios-feature-detection/).I ran about 170 feature tests (
CSS.supportson properties and selectors, plus JS globals and prototype members) in Safari on the 18.2, 26.5 and 27.0 iPhone simulators, looking for anything that separates 26.5 from 27.0. Nine do:18.2 26.5 27.0 overflow-anchor: autofalse false true width: stretchfalse false true appearance: base-selectfalse false true selector(::checkmark)false false true selector(::picker(select))false false true selector(:heading)false false true Element.prototype.ariaNotifyfalse false true WebAssembly.Suspendingfalse false true shape-outside: shape(from 0 0, line to 1px 1px)false true false Why
overflow-anchoroverVersion/:- It is about the same subsystem. Scroll anchoring has the engine adjust the scroll position while the user is scrolling. I have not shown it is what makes momentum survive a write, only that both arrive in the same release, but it is a less arbitrary proxy than the others in the table.
- It does not read the UA, so it should give the same answer in in-app WKWebViews and in Chrome/Firefox on iOS, which is where
Version/may be missing. - It fails the same way: when it is false the deferral stays as it is today.
So the check would be
isIOSWebKit() && CSS.supports('overflow-anchor: auto')for "momentum survives a write", possibly withVersion/ >= 27as a second signal.What this rests on, and what it doesn't:
- One simulator per version, one page load each. Not yet run on the 27.0.1 iPhone, in a WKWebView, or in Chrome/Firefox on iOS.
- Nothing between 26.5 and 27.0. If a later 26.x exists I don't know which side it falls on, for either the momentum change or
overflow-anchor. - It is a correlation between two things in one release. If WebKit ever ships one without the other, the check is wrong, and in the "true but momentum still stops" direction it would bring back the stopped momentum.
One thing this raises for the redesign: if Safari 27 anchors natively, it may compensate some resizes itself. In the iPhone run above, a row resized above the viewport left the content shifted by 50px until the flush, which suggests it does not for transform-positioned rows, but that run was not set up to test it.
piecyk changed the title
@phcorp when you have time, could you take a look at the stacked PRs from the plan? Review in order; each one only adds its last commit:
1 .#1309: resizes before a scroll write's read-back are left to reconcile (fixes your stale scrollOffset case from #1308) 2. #1310: a user scroll ends a non-smooth scrollToIndex before it lands (fixes the two pull-back cases) 3. #1311: refactor, the scroll state as one phase instead of flags (no behaviour change)
@piecyk I went through the three PRs. Details are on each; the short version:
PR Result #1309 The fix works in Chromium, Firefox and WebKit. One regression: scrollBygets stuck at the top and bottom edge, because a write that does not move the element never clears_lastWrittenOffset. Clamping thescrollBytarget fixes it.#1310 The fix works in the three browsers, and no regression found. It also removes the chat.spec.tsflake in Chromium. Two questions on the PR: a custom animatedscrollToFn, and a clamped read-back with the target below the new max.#1311 No behaviour difference from #1310 in 55,000 random event sequences, with every phase and transition reached. How I checked. Unit suites on
mainand each head (same counts as your descriptions). Single-line mutations of each change against its tests. A frame-loop model run over 34,200 index scrolls on the four revisions. A plain-DOM page onvirtual-corein real Chromium, Firefox and WebKit for the headline cases. The react-virtual, Marko and Angular e2e suites on the four revisions,--retries=0.E2E. Nothing fails on a PR that does not also fail on
main. What is flaky here, 40 repetitions per revision in interleaved blocks of 10:Test Browser main#1309 #1310 #1311 chat › keeps visible messages stable when history is prepended Chromium 18 19 40 40 chat › does not follow appended messages while reading history Chromium 29 37 40 40 smooth-prepend › a prepend mid-flight does not abandon a smooth scrollToIndex WebKit 26 24 28 34 smooth-scroll › index 500, start alignment WebKit 23 21 31 25 smooth-scroll › index 500, center alignment WebKit 33 35 33 32 - The Chromium chat flake is the one I reported in #1308, and #1310 fixes it.
- The WebKit smooth-scroll failures are on every revision. With
--workers=1(20 repetitions)smooth-prependgoes to 19, 18, 20, 20, so that one is load. "index 500, start" still fails 20–30% everywhere includingmain(16, 14, 15, 16 of 20), landing 4–128px off onmain. That looks like a flake that predates these PRs. - Firefox: 39/39 on every revision, three runs each. Marko chat at 20 repetitions: 320/320 on every revision. Angular: 14/14.
Two things I ran into that are not from these PRs:
- An end-aligned
scrollToIndexcan settle off its target onmainand on all three heads. In the model, 400 rows with mixed sizes,scrollToIndex(272, { align: 'end' }): the write lands, rows above the viewport are corrected by +21px, rows inside it change by −21px, so the target does not move and reconcile never rewrites. The row ends 21px short, and onmainand #1309 the scroll state stays alive until the 5s valve. Model only, not checked in a browser. - The Marko e2e build sometimes drops a route: every test of one spec file fails with zero rows rendered, and the build has 83 asset files instead of 86. Seen once on
mainand once on #1309, on different routes. I did not find the cause.
Not covered: nothing ran on a real iOS device, so the finger-down cases in #1310 rest on the unit tests and on my earlier device runs for #1308.
Plan update#
Status after the first round, and what changed in the plan.
Step Status 1. Stale scrollOffsetbefore a write's read-back#1309, released in 3.19.1 2. Pull-back of an index scroll that never landed #1310, released in 3.19.1 2a. Scroll state as an explicit phase #1311, released in 3.19.2 touchcancelhandled liketouchend(part of 2b)#1314 (thanks @mrosberghaus), released in 3.19.2 2c. Behaviour snapshot + scroll-state refactor #1316, merged; to be released alone as 3.19.3 2d. Snapshot timers with due times #1316, merged 2b. Defer only for touch-driven scrolls ready on top of #1316; PR after 3.19.3 New: 2c. Behaviour snapshot and one owner per piece of state (#1316, merged)#
Each fix in this area added a flag with its own resets, and fixes started to go in circles: #1309's written offset needed four more resets after review, and the "iOS is in motion" condition existed in three copies. #1316 adds a seeded behaviour snapshot (
tests/scroll-trace.test.ts, observable output only) and, with the snapshot unchanged, gives each piece of state one writer and one place that clears it:pendingWritefor a write until its read-back (replaces_intendedScrollOffset,ScrollState.writtenOffset, the storedscrollAdjustments);_iosTouch(down/tailowning its timer) and one_iosInMotion()check (replaces three flags and three copies of the gate);- the pending prepend anchor as a tagged record;
_startScrollas the one entry point for every scroll command.
Diagrams of the resulting flows are in the #1316 description. @phcorp's differential run (50,000 seeds) found two differences beyond the declared one, both fixed or pinned before merge: a regression in
scrollToIndexwith no target (fixed), and the element-swap read-back (kept, listed as a second exception). With those accounted for, base and head were identical, internal state included. Released alone, so it can be avoided by pinning 3.19.2.New: 2d. Snapshot timers with due times (#1316, merged)#
The snapshot first fired all pending timers at once, so it could not see timing: the 150ms tail at 50ms or 1500ms left it unchanged, and it missed the touch-tail change in #1316. 2b is about timing (the tail closing, re-armed by momentum frames), so timeouts now fire at their due time. Each of those tail mutations now changes 9 of 18 configurations.
2b. Defer only for touch-driven scrolls (revised, ready)#
Scope is unchanged; on #1316's structure it is a few edits:
_iosInMotion()dropsisScrolling: only a touch defers (fixes #1250).- A scroll event while
_iosTouchis in itstailre-arms the tail, so it spans the fling and closes ~150ms after the last momentum frame. - An absolute command closes the tail, in
_startScroll. - #1305's "drop corrections during an index scroll" goes; reconcile's retarget clears the deferral instead.
touchcancel: done in #1314.
Acceptance, all met on the local branch: the snapshot moves only iOS rows (347 of 540 iOS seeds), every web row unchanged; all 12 known divergences in
tests/ios-differential.test.tsconverge; four of @phcorp's #1308test.failspass (a gesture,cancelScroll, the safety valve, andscrollByeach ending an index scroll before it retargets keep the resize correction; already green on the old 2b branch, asserting row positions only). Device check with the #1308ios-deferralpage. About 15 iOS tests that model momentum as scroll events without touch events get rewritten with explicit touches.3. iOS 27+ (unchanged)#
Now one condition on the tail inside
_iosInMotion().4. Per-row deferral record (extended)#
Still needed for the last #1308
test.fails, "a correction is not replayed once the viewport is above the resized row" (the reverse flick): one summed delta cannot tell whether the viewport has passed the row.Also fold the iOS flush into
scrollOffsetthe wayapplyScrollAdjustmentalready does, soscrollAdjustmentsis always 0 and stays only as a getter for the documented custom predicate. Both replace_iosDeferredAdjustmentcode, so they belong together.5. Shared stalls and prepend fixes (refined)#
For the deferred prepend correction applied twice: make "a deferred delta is never already in
scrollOffset" an invariant (un-fold the anchor delta when it is deferred, or don't defer it), rather than adding a flag.Later, decide after step 4#
scrollOffsetas browser truth only, with an effective offset derived from the pending write. It would remove the eager folds and the remainingscrollAdjustmentsterms, but it changes what the publicscrollOffsetmeans mid-prepend.Open findings, not scheduled#
- An end-aligned
scrollToIndexcan settle off its target when corrections above and inside the viewport cancel out (21px in @phcorp's model; onmainand all heads; not checked in a browser). - A clamped read-back below a target that shrank before it reads as a user scroll; pinned with a
.failstest in #1310, not seen in a browser. - A custom
scrollToFnthat animates (the smooth-scroll example) ends an index scroll on its first frame; out of scope untilscrollToFncan say it animates. - A resize before a
scrollBy's read-back is not added to the relative target (CodeRabbit on #1309);scrollBylands where it was written, better than 3.19.0.
Open findings from @phcorp's simulator run on #1318 (also on main)#
- A row removed mid-touch leaves the touch
down:touchendfires on the detached node and never reaches the scroll element, so the deferral stays on until the next touch. Possible fix: also listen fortouchend/touchcancelon the touch's own target. - A long task mid-fling (250ms on 26.5) lets the tail close and the flush write, which stops the fling.
- iOS 27: momentum can override a programmatic jump. On the 27.0 simulator a write mid-momentum shows for one frame, then momentum continues:
scrollToIndex(200)mid-fling ends near 1000, not 10000. Input for step 3; check on a device first. - Rubber-band frames can be 116–134ms apart, against the 150ms tail. The tail may need to be longer, or measured against the actual frame rate.
- A row removed mid-touch leaves the touch
Plan update: #1287 joins step 5, and the order from here#
Step 5's main item is now #1287 (draft #1319). A trace on iOS 27 showed #1287 isn't desktop-only: a prepend that lands while
scrollTopcan't be written (the iOS deferral, or the desktop rubber band) shows the new rows and then snaps back on iOS, and freezes the bounce with a blank top on desktop. #1319 holds the correction instead:getVirtualItems()andgetTotalSize()are reported shifted back by the held amount so the rows stay put, nothing is written while overscrolled, and one write releases the hold when it's safe. Verified on an iPhone 17 Pro (iOS 27.0.1) and desktop Safari 18.4; details and traces on #1287. It replaces_iosDeferredAdjustment.Correction to step 5: in those traces the "deferred prepend applied twice" did not happen (the bounce's scroll events overwrote the eager offset first). It can still happen when no scroll events arrive in between; #1319 may remove it along with the deferral, to be confirmed with a test.
Order from here:
- 2b, #1318: after #1317 (3.19.3) is released.
- Step 5's hold, #1319: stacked on #1318; its description lists what's left before it leaves draft.
- Step 3 (iOS 27): "don't defer during momentum on 27+" becomes one condition in #1319's write-possible check. Coming after #1319 keeps it small; coming before step 4 shrinks step 4 to the finger-down phase on 27+. Input from @phcorp: on 27, momentum can override a programmatic jump.
- Step 4 (per-row record): becomes a per-row hold on top of #1319: hold each row's correction separately and, when releasing, apply only the rows still above the viewport. Still a decision to make with the #1308 device page. The reverse-flick
test.failsstill fails with #1319. - The rest of step 5: the
scrollToOffset/scrollBystall, and the anchor sync from a stale offset before an index scroll's read-back. - Then a note on #884, asking for a retest on a version with all of the above.
Status update: 2b merged, step 5's hold ready for review#
Step Status 1, 2, 2a, 2c/2d merged and released (#1309, #1310, #1311, #1316) touchcancelliketouchend#1314, released 2b. Defer only for touch-driven scrolls #1318 merged, to be released on its own 5. Hold a correction while scrollTopcan't be written (#1287)#1319 ready for review 3. iOS 27 momentum next 4. Per-row record after step 3, still a decision Rest of step 5 after step 4 2b (#1318). Besides the touch gate, @phcorp's simulator run found two regressions before merge, both fixed with tests that failed first: iOS ignores a write only under a dragging finger, not a resting one (the
downtouch now recordsdragged, set only by a scroll event that moved the position and isn't our own read-back), and the touch listeners now run in the capture phase so a row callingstopPropagation()can't hide a gesture.Step 5's hold (#1319). Verified on an iPhone 17 Pro (iOS 27.0.1) and desktop Safari 18.4 with the chat example (traces on #1287). Since the draft, a fresh-context review found and fixed one bug: the flush could write the pre-command offset over a scroll command that had just closed the touch tail; it now writes the pending command's own target. The behaviour snapshot also records where the first row renders, not only which rows, so it can see the hold's row shift.
scrollOffsetkeeps layout coordinates during a hold, documented in the API docs. Benchmarks show no measurable cost.Order from here (unchanged): #1319 → step 3 (iOS 27: one condition in #1319's write-possible check) → step 4 as a per-row hold (decide with the #1308 device page; the reverse-flick
test.failsstill needs it) → the rest of step 5 (thescrollToOffset/scrollBystall, and the anchor sync from a stale offset before a command's read-back) → a retest note on #884.Still open, not scheduled: a row removed mid-touch leaves the touch
down; a long task mid-fling lets the flush stop the fling; rubber-band frames 116–134ms apart against the 150ms tail; on iOS 27 momentum can override a programmatic jump (input for step 3); the end-alignedscrollToIndexsettling short (model only); the clamped read-back below a shrunk target (test.fails).@phcorp, we're close to closing this one. Two PRs are left, and your help on either (or both) would be great:
#1319 – hold corrections while the user is scrolling (ready for review) This replaces the iOS deferred adjustment with a single "hold": while a correction can't be written, rows are exposed shifted by the held amount, so nothing moves on screen until the hold is written. A code review would help most here. The core rule: rendered rows = layout positions minus the hold, and the hold is written only when writing is allowed. The chat example (
examples/react/chat) is the quickest way to try it on a device.#1324 – iOS 27 flings, command stalls, no more
test.fails(draft, stacked on #1319) This needs real iOS checks before it leaves draft, and you have the 27 setup:- iOS 27:
scrollToIndexmid-fling lands about 150ms after the fling stops, with no one-frame flash.- A drag during that wait cancels the command; a tap does not.
- A command issued at rest is immediate.
CSS.supports('overflow-anchor: auto')istrue.- Native anchoring: turn corrections off with
virtualizer.shouldAdjustScrollPositionOnItemSizeChange = () => false, grow a row above the viewport while at rest, and check thatscrollTopdoesn't move on its own. If it does, the browser also anchors, so corrections would be applied twice.
- iOS 26.x:
CSS.supports('overflow-anchor: auto')isfalse, andscrollToIndexmid-fling still writes at once.
Device or simulator results are both useful; just say which you used. A short "pass/fail per line" reply is plenty.
Once both are merged and released, I'll ask the reporters of the linked issues to retest and then close this one.
- iOS 27:
To help review #1319 and #1324, here's every piece of state behind the scroll-correction logic as of #1324 (which includes #1319), with where each one was introduced.
Stored state#
Name What it holds From scrollOffset/scrollDirection/isScrollingScroll position in layout coordinates, direction, and whether the user is scrolling main scrollStateThe running scroll command ( scrollToIndex/scrollToOffset/scrollBy/scrollToEnd): target index or offset, alignment, start time, last target, stable-frame countmain ├ phasesmooth/smoothLanded/smoothFinishing/instant: how the command is moving and how its scroll events are readmain └ awaitingTailOn iOS 27, a command issued mid-fling isn't written yet; it waits for the fling to end. A drag cancels it, a tap doesn't #1324 pendingWrite{target, smooth, adjustments}Our last write, kept until a scroll event reports it back. Tells our own read-back apart from a user scroll main pendingScrollAnchorWhat setOptionsdecided for_willUpdate: keep the reader in place after a prepend (anchor), or follow an append (follow)main _holdOffsetCorrections that couldn't be written yet. Rows and total size are exposed shifted by it until it's written #1319 (replaces _iosDeferredAdjustment)_reportedOverscrollThe last scroll event was past an edge (rubber band), so a write now would be discarded #1319 _iosTouchiOS gesture: down {dragged}while the finger is on the screen,tail {timerId}for ~150ms after it lifts,nullotherwisemain └ tail.momentumWhether a fling can be running (the finger dragged), or the tail is just a tap #1324 _clampedAdjustmentA correction write the browser clamped because the sizer hadn't grown yet; retried once it has (#1258) main _resizeBatchA ResizeObserver batch in progress; one notify at the end instead of one per row main _isIOSResultCached result of the "is this iOS WebKit?" check main _iosMomentumOverridesWritesResultCached iOS 27 gate: CSS.supports('overflow-anchor: auto')on iOS#1324 Derived checks (computed when needed, no stored state)#
Name Answers From scrollAdjustmentsCompensation written but not yet reported back ( pendingWrite.adjustments)main getCommandWrittenOffset()Where the current command's unreported write put the element main _iosInMotion()/_iosDragging()A touch gesture owns the scroll / a finger is dragging, so iOS ignores writes main _canWriteScroll()Would a write land now? Not during iOS motion, not while overscrolled #1319 _clampedBy(target)Would this write be clamped by the element's current max? #1319 isReadBackLocal, in the scroll handler: this event is our own write reported back (within 1.5px) main isClampedReadBackLocal: our write, reported back clamped at the max because the sizer shrank; not a user scroll #1324 _awaitingCommandReadBack()A command's write hasn't been reported back yet, so the prepend anchor and offset corrections must wait #1324 Actions#
Name Does From _flushHoldIfReady()Writes the hold once possible; rows go back to layout coordinates in the same paint #1319 _openIosTail()/_endIosTouch()Start or restart the 150ms tail; clear the gesture record and its timer main _writeAwaitingCommand()When the tail closes, writes the waiting command with its target recomputed from the current layout #1324 _followOffsetTarget(delta)Moves an offset command's target along with a correction, so the command finishes instead of running until the 5s safety timeout #1324 _retryClampedAdjustment()Rewrites a clamped correction once the sizer has grown main Net change against main#
- #1319:
_holdOffsetreplaces_iosDeferredAdjustment, and_reportedOverscrollis added, so +1 stored value. - #1324:
awaitingTailandtail.momentumare added, plus one cached platform check, so +3. Only the first two change at runtime.
So both PRs together add 3 runtime flags and 1 cached platform check. Most of the new logic is in derived checks (
_canWriteScroll,_awaitingCommandReadBack,isClampedReadBack), which can't fall out of sync with the stored state. When reviewing,awaitingTailandisClampedReadBackare the two worth questioning most: each fixes one specific case, the iOS 27 command mid-fling and #1310's clamped write.- #1319:
Follow-up after #1319 and #1324: simplify the scroll state#
The state list above is hard to reason about, so I asked for an independent design review. In short: part of it is inherent (there are four separate reasons a scroll write can't be trusted: a dragging finger, iOS momentum, the rubber band, and a sizer that hasn't grown), and the hold from #1319 is the right building block for those. But the rest has piled up one bug at a time, and that needs fixing.
What piled up
- Five places encode the same thing, "the layout position is ahead of the element by X":
pendingWrite.adjustments,_holdOffset, the prepend anchor'sdelta,_clampedAdjustment, and a command write that hasn't been reported back yet. - Each has its own "is this scroll event ours?" check, and they all meet in the scroll handler. That read-back logic is the hardest part to follow.
scrollAdjustmentsis effectively always 0:applyScrollAdjustmentadds it intoscrollOffsetand resets it right after the write. The public getter stays, but the internal plumbing is a leftover.
The mental model we're aiming for, four questions
- How far is the layout position ahead of the element?
- Who owns the scroll right now: the user, a command, or nobody?
- Can a write land right now?
- Is this scroll event our own write coming back?
Plan: one refactor PR after #1324, with no behaviour change. The proof is that
scroll-trace.test.ts.snapstays byte-identical.- P1: one
_classifyScrollEvent()returning'spurious' | 'readBack' | 'clampedReadBack' | 'clampedEcho' | 'external', replacing the scattered checks in the scroll handler - P2:
scrollState.awaitingTailbecomes aqueuedphase ofScrollPhase(the command stores itsbehavior) - P3:
_iosTouch'sdraggedandtail.momentummerge into onemovedflag - P4: remove the internal
adjustmentsplumbing (pendingWrite.adjustments,+ this.scrollAdjustmentsat the call sites); keep the public getter
Separately, with its own release because it changes behaviour
- P5: treat the prepend anchor as a hold, so
pendingScrollAnchoronly keepsfollow. The snapshot moves, React gets one extra render per prepend, and anchors gain the #1258 clamp retry. - P6 (maybe): merge the hold and the clamp retry into one field. Reassess after P1–P4.
Kept as is: the hold invariant,
pendingWriteread-back matching (1.5px tolerance), the smooth-scroll phases,_followOffsetTarget, the iOS 27 gate as its own check (corrections are held for the whole gesture, while commands wait only for a 27 fling), and the rule that only one function cancels the tail timer.- Five places encode the same thing, "the layout position is ahead of the element by X":
Update: the scroll-state refactor is done#
Follow-up to the plan above.
Where things stand
- #1319 (the hold) is merged.
- #1324 now has the iOS fixes plus P1–P4, folded into one PR. #1324 was still a draft, and the refactor rewrites most of the code it adds, so reviewing #1324 first and then its rewrite would mean reading the same logic twice. With the refactor in the same PR, it gets read once, in its final shape. The refactor commits come after the fix commits, so they are easy to tell apart.
- #1325 moves the iOS touch gesture into its own
IosGestureclass, stacked on #1324.
Proof that the refactor changes no behaviour:
scroll-trace.test.ts.snapstayed byte-identical after every refactor commit (27 traces × 60 seeds, web / iOS / iOS 27), andpnpm run test:pris green.The plan, ticked off
- P1:
classifyScrollEvent()→'spurious' | 'readBack' | 'clampedReadBack' | 'clampedEcho' | 'external', a pure function insrc/scroll-classifier.tswith a truth-table test, run once before the handler writes any state - P2:
awaitingTail→ aqueuedphase; the command stores itsbehavior - P3:
dragged+momentum→ onemovedflag - P4: the internal
adjustmentsplumbing is gone;scrollAdjustmentsis@deprecatedand always 0 - P5: prepend anchor as a hold (changes behaviour, so it gets its own release)
- P6 (maybe): merge the hold and the clamp retry
Added beyond the plan
externalRetiresCommand(): the "user took over" decision as a pure function. The target is computed lazily, so the measurements cache is rebuilt for exactly the same events as before._toLayoutOffset()gives a name to the conversion from the element's offset to the layout position (question 1).- A test for a
scrollToFnthat reports its write back synchronously. Without the guard, the correction lands twice. - The
IosGestureclass (#1325), with fake-timer unit tests.
What we learned
scrollAdjustmentsreally was 0 at every observable point while enabled. The only exception wasenabled: false: corrections made while disabled used to accumulate and could be added after re-enabling. That edge case is listed as a behaviour change in #1324.- Dropping the clamp retry can't be derived from the event kind: a read-back within 1.5px of the clamped max must keep the retry. So it stays its own check, and the classifier test pins it.
- After P1–P4, three stored values still say how far the layout is ahead of the element (
pendingWrite.target,_holdOffset,_clampedAdjustment), plus the anchor'sdelta. P5 and P6 would bring that down to one.
Next: #1324 needs its device checks (iOS 27, iOS 26, desktop Safari) before it leaves draft. Then #1325, then P5.
@phcorp, quick update since I asked for your review this morning, things got a bit out of hand ;)
- #1319 is merged 🎉
- I folded the scroll-state refactor (plan) into #1324. It rewrote most of what #1324 added anyway, so this way you only read the final version. The trace snapshot didn't change across the refactor. A fresh review also caught one more stalled
scrollToOffsetcase (prepend held insetOptions), fixed in3f725bd2. - #1325 pulls the iOS touch handling into an
IosGestureclass, no behaviour change.
Heads-up, my state table from this morning is a bit stale now:
awaitingTailbecame aqueuedphase,draggedandtail.momentumare a singlemovedflag, and the read-back checks live inclassifyScrollEvent().If you get a chance, two things would help most:
- Checking
CSS.supports('overflow-anchor: auto')on your 27.0.1 iPhone and in a WKWebView. We've only seen it on the simulator so far, and caniuse still says unsupported on 27.0–27.2. - The device checks in #1324:
scrollToIndexmid-fling should land after the fling without a flash, and a drag while it waits should cancel it but a tap shouldn't.
Thanks!
@piecyk replying to https://github.com/TanStack/virtual/issues/1307#issuecomment-6168180759, both points.
Results for #1324 at 3c41e3cd, compared with main at 3c61b6e3. Simulators: iOS 27.0 and 26.5 (Safari and a minimal WKWebView app), 3 runs each. iPhone 16 Pro on 27.0.1: real finger, 1–3 runs per check.
iOS 27
Check Sim 27.0 iPhone 27.0.1 scrollToIndexmid-fling lands ~150ms after the fling stops, no flashpass 3/3 (main flashes one frame, then ends near 1000) pass 1/1 (+152ms) a drag during the wait cancels it fail 3/3 fail 3/3 a tap during the wait does not cancel it pass 3/3 pass 2/3 (one run: the write showed one frame, then the command was dropped) a command at rest is immediate pass 3/3 pass 1/1 CSS.supports('overflow-anchor: auto')true in Safari and WKWebView true in Safari native anchoring (corrections off, a row above grows at rest) pass 3/3: scrollTopstays, the row moves 50pxpass 1/1 iOS 26.5:
CSS.supports('overflow-anchor: auto')is false in Safari and WKWebView, andscrollToIndexmid-fling writes at once and lands (3/3), as on main. The WKWebView UA has noVersion/token, so the CSS check is the only usable signal there.Why the drag case fails: a touch that lands during a fling fires no touch or pointer events at all, not even on
windowin the capture phase. Seen on both simulators (11/11 runs on a plain list) and on the iPhone (6/6 runs with a second touch during the glide). So_iosTouchnever sees the drag, and the queued command fires once scroll events stop for 150ms:- the finger catches the fling and holds still: written under the finger, the target shows ~95ms, then the drag carries on and the command retires;
- the drag ends in its own glide: written when that glide stops, which yanks the user to the target.
A cancel would have to come from the scroll events themselves, for example a reversal against the fling. I haven't tested that.
The two regressions from my #1318 run (resting finger,
stopPropagationin a row) are fixed on main and here, 3/3 on both simulators.Not run: WKWebView on the device, and #1324's desktop Safari, Chromium and Firefox checks.
Thanks @phcorp, the missing touch events were the key. I could reproduce everything on my iPhone (27.0.1), including a second flick during a fling, which also sends nothing. It's the most common case, since that's just how people scroll.
c6188ae8in #1324 now reads the takeover from the scroll events while a command waits: a turn back, a speed-up (last 40ms ≥2× the 40ms before), or the fling stopping at speed (a finger caught it; iOS undoes a write under that finger anyway). So a tap during the wait now cancels too. That's a change from what I wrote before, but writing under the finger wasn't possible. The tests replay my recorded traces.It also explains your one bad tap run: the 150ms timer can run out while the end of a fling is still moving. The timer now checks the element first.
On my iPhone, all four cases pass: lands when left alone, and cancels on a drag back, a second flick, or a tap. A re-run on yours would be great, especially in WKWebView on the device.
@piecyk replying to https://github.com/TanStack/virtual/issues/1307#issuecomment-6171658718: re-ran #1324 at c6188ae8 on my iPhone (27.0.1) in Safari, Chrome and Firefox (both WKWebView), one run per case per browser, plus the 27.0 simulator (2–3 usable runs per case).
Case iPhone: Safari / Chrome / Firefox Sim 27.0 fling left alone lands +150–152ms after the fling stops, 3/3 2/2 drag back during the wait cancelled, 3/3 3/3 second flick cancelled, 3/3 2/2 tap while it still glides fast cancelled, 3/3 2/2 tap near the end of the glide not cancelled: the command lands, 3/3 2/2 CSS.supports('overflow-anchor: auto')true in all three true Two things:
- A late tap reads as the fling ending. My late taps stopped the glide at 0.21–0.35px/ms, under
flingCaught's 0.5px/ms, so the command was written 151ms later and landed. No flash, since the finger had lifted by then. But it doesn't match "a tap now cancels too", and a longer press at that speed would likely bring back the undone write from my first round. - The tail can close before the fling starts (simulator, 3 of 15 runs). When the first momentum event came 159–253ms after
touchend, the tail had already closed, so a command issued mid-fling was written at once and overridden after a 1–2 frame flash. The new element-moved re-check only runs while a command is queued. It's the long-task case from before, with a new consequence on 27.
- A late tap reads as the fling ending. My late taps stopped the glide at 0.21–0.35px/ms, under
Thanks @phcorp, both fixed in
75b04923(#1324):- Late tap:
flingCaughtnow triggers at 0.05px/ms. Every natural end in my recordings fades to 0.015px/ms or less, and your late taps were 0.21–0.35. When the tail waits again because the element moved with no scroll event, that position is recorded too, so a fling that keeps moving silently isn't read as caught. A tap in the very last pixels of a fling still reads as its end. - Tail closing before the first frame: after a drag, the code remembers that its fling hasn't reported yet. If the first frame comes after the tail closed, within 1s, it reopens the tail. Only after a real drag, never after a tap or our own writes, so #1250 is safe. That also covers iOS 26 and earlier, where a correction written into that fling would stop it.
Tests use your numbers (0.21px/ms tap, a first frame 250ms late). If you can re-run the late tap and the simulator case, that would close it out.
- Late tap:
@piecyk replying to https://github.com/TanStack/virtual/issues/1307#issuecomment-6174481171: re-ran #1324 at 75b04923 on the 27.0 simulator (3–5 runs per case) and my iPhone (27.0.1, Safari).
Case Sim 27.0 iPhone 27.0.1 late tap cancelled 3/3 (c6188ae8 landed 2/2) cancelled 3/3, but my taps stopped the glide at 0.56–1.16px/ms, so they don't exercise the new threshold fling left alone lands 3/3 lands 2/2 (+152ms) late first frame, flick that scrolled before lifting lands 5/5 not run late first frame, flick that lifted before any scroll event lost 1/1: tail not reopened, written mid-fling, gone after 2 frames not run The last row: the reopen is armed only when
movedwas set while the finger was down. On my iPhone, 2 of the recorded flings lifted before any scroll event (43ms and 88ms touches), so a quick flick plus a late first frame isn't covered. Without the late frame it's fine, since the first momentum frame marks the tail moved.Caveat: I provoked the late frame with a 250ms long task in a
touchendlistener, and that did not reproduce the original failure on c6188ae8 (6/6 fine, and the 26.5 correction case was held through the fling on both heads). So these runs show the gap, not the fix working against the old behaviour.Thanks @phcorp, and thanks for the caveat about the long task; that's useful to know.
I'm going to stop adding heuristics to #1324 here. The quick flick plus late first frame needs three rare things at once, it behaves exactly as on
main(the command is lost after a short flash), and we can't reproduce it reliably, so I'd rather not add another rule I can't verify. I've listed it as a known limit in the PR, with the likely fix (count the finger's travel betweentouchstartandtouchendas moved) if anyone hits it.The rest is confirmed across your runs and mine: on 27 a command waits for the fling, lands when left alone, and cancels on a drag, a second flick or a tap. Next I'll finish the remaining desktop and iOS 26 checks and get #1324 merged.
The plan in this issue is complete. All steps are merged.
Step PR 1. Stale scrollOffsetbefore a write's read-back#1309 2. Pull-back of an index scroll that did not land #1310 2a. Scroll state as one phase #1311 2b. Defer only for touch-driven scrolls #1318, with the hold in #1319 3. iOS 27 momentum #1324 4. Per-row record Not necessary after the hold in #1319 5. Shared stalls and prepend fixes #1324 Refactor: IosGesture#1325 Answers to the open questions:
- Safari 27 native scroll anchoring does not move
scrollTopfor these rows. The corrections do not double. - In-app WKWebViews and Chrome and Firefox on iOS work. @phcorp tested them.
Device checks: two iPhones on iOS 27.0.1, the 27.0 and 26.5 simulators, desktop Safari with a trackpad, and Chromium, Firefox and WebKit in Playwright.
Follow-ups that are not part of this plan:
- #1327: a clamp retry can overwrite a scroll command.
- Known limits on iOS 27, listed in #1324: a quick flick with a late first frame, and a finger that stops a fling and stays on the screen.
Thank you @phcorp for the many device runs and traces.
- Safari 27 native scroll anchoring does not move
piecyk closed this
Sign in to join this conversation.
I went through this measuring each claim rather than reasoning about it: hand-ordered unit probes against
main(28a21741), then the same orderings in real iOS Safari on the 18.2, 26.5 and 27.0 simulators and on an iPhone 16 Pro running iOS 27.0.1, using an instrumented page that logs scroll/touch events,scrollToFnwrites andresizeItemcalls. Gestures were real touches with native momentum. 18.2 and 26.5 gave the same results as each other unless noted; iOS 27 differs on one point, and it is the important one.Edited three times: added the 18.2 gesture runs, the finger-down and smooth-scroll cases, the physical-device runs and an iOS 27 simulator; corrected two rows that the first version listed as not reproduced, and the premise paragraph.
The premise no longer holds on iOS 27. A
scrollTopwrite that changes the position mid-momentum:+50writeA no-op write (
+= 0) never stops momentum on any of them. So this is the OS version, not simulator vs hardware: on 27 the write is applied and the momentum carries on. There the deferral only delays the correction. On the iPhone a row resized above the viewport left the content shifted by 50px for 3.3s of momentum, then the flush moved it back. Worth deciding before the redesign whether the deferral should be skipped on 27+ for the momentum phase.While a finger is down it is different: the write is ignored and the drag carries on, on 18.2, 26.5 and the 27.0.1 iPhone alike (see below). So the touch part of the deferral still matters on 27.
Confirmed#
cancelScrollbefore the retarget write loses the resize (#1305 gap)setTimeout(0)or rAF later, reconcile has already written and it lands correctlyscrollByreplacing an in-flight index scroll drops the correctionscrollToIndexunder a finger the state was still alive when logging stopped, up to 3.7s laterscrollToIndexduring momentum stops the momentum and lands normally. Under a finger it turns into the pull-back belowWorth knowing for the #1305 gap: on device the index-scroll state is retired two frames (~33ms) after landing. A resize that arrives later goes through the ordinary deferral and is flushed correctly, also when
scrollByfollows it. So the gap is "something ends the index scroll between a measurement and the next rAF".Needs correcting in the issue#
dropScrollStateis not onmain. #1306 was closed unmerged; the three exits are stillthis.scrollState = null. The "#1306" table row and the "prepend + resize + gesture … #1306's at-target guard" item describe code that never landed.scrollOffsetitem is not iOS-specific and is worse than described. If a row measures between thescrollToIndexwrite and its scroll event, the adjustment is written against the old offset and overwrites the index scroll: scrolling up from 2000 to row 10 ends at 2050 instead of 500, and reconcile never re-issues the write because the target did not change. Reproduced in real iOS Safari by forcing ameasureElementin that window (15050 instead of 5000). With natural ordering it lands correctly on iOS and Chromium, though I did see oneresizeItemfall inside the window on iOS whenscrollToIndexwas called from a scroll handler. On iOS the #1305 drop hides it whileisScrollingis true. I'd track it separately.scrollTopwrite while a finger is dragging (10 of 10 runs across 26.5, 18.2 and the iPhone: write to 10390, next scroll event at ~20). The index scroll therefore never lands,hasReachedTargetstays false, the drag is not treated as an interruption, and the state stays alive. Reconcile writes nothing on its own, but the next measurement that moves the target makes it write again. On 26.5 that happened in 4 of 6 runs once the finger lifted: a row first-measured during the user's own momentum and the view jumped from ~240 to row 200 at 10660. In the other runs, in all three on 18.2 and in the one iPhone run, the state was still pending when logging stopped. Dragging against a travelling smoothscrollToIndex(26.5) behaves the same way: the touch stops the animation, no write follows, the state stays alive.iOS deferral:tests onmainassert the private_iosDeferredAdjustmentvalue, so they cannot survive removing it unchanged. The tests from #1306 are not in the tree.On the proposal#
shouldAdjustScrollPositionOnItemSizeChangereturning false defers nothing, and the first measure of the row spanning the viewport top is compensated (rows below stay put). An anchor on the first visible row would compensate the first two and not the third.A variant that fits the measurements better: keep what was deferred per row (key → delta, plus prepend shifts) and decide at flush time which of those rows are above the current offset. That fixes the reverse-flick case, keeps momentum travel correct, needs no capture offset, and keeps the existing predicate. The index-scroll exits are a separate cause (the delta is discarded while
scrollState.index != null) and could be handled by keeping it in the same per-row record instead of dropping it.I have these pinned as tests (seven
test.failsfor the cases above, five passing ones for the behaviours in point 6 and the momentum baseline) and the instrumented page as an e2e app entry; happy to open a PR with them if useful.Still not covered: versions between 26.5 and 27.0 (I don't know where the momentum behaviour changed), the smooth-scroll drag anywhere but 26.5, the scripted same-task cases on iOS 27, and the safety-valve loss end to end.