Skip to content
Source
Sign inSign up
TanStack/virtual

iOS scroll-correction deferral: per-row record, iOS 27 momentum, and index-scroll exits #1307

Closedpiecyk opened this issue 23 comments
piecykcommented

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

PhaseiOS ≤ 26iOS 27+
Finger downa scrollTop write is ignoreda scrollTop write is ignored
Momentuma write stops the momentumthe 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_7 on 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 scrollOffset before 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 hasReachedTarget for 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 after touchend. 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); touchcancel is handled like touchend.
  • 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.ts converge and fixes three #1308 test.fails (cancelScroll, the safety valve, scrollBy replacing an index scroll). About 15 existing iOS tests model momentum as scroll events without touch events and need rewriting with explicit touchstart / 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 by Version/ >= 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: none on the scroller.
  • Tests: jsdom with CSS.supports stubbed 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 main read _iosDeferredAdjustment. The ones that pin what was deferred move to a small read-only accessor or to position assertions. Two #1308 test.fails have 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 a scrollToIndex: 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): setOptions folds the anchor delta into the tracked scrollOffset eagerly, and when the DOM sync is deferred under a finger, the flush writes scrollOffset + deferred. A fling to the top that lands on a prepend jumps by the prepend's height.
  • #1250: fixed by step 2b (partly by #1305 already: scrollToIndex sags for one frame instead of snapping later; scrollToOffset still snaps).
  • #884: the reason the deferral exists; addressed on main since @tanstack/virtual-core 3.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 scrollToIndex cancel it? Today it doesn't until the target is reached.
  1. phcorp(GitHub profile, opens in a new tab)commented

    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, scrollToFn writes and resizeItem calls. 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 scrollTop write that changes the position mid-momentum:

    RunsAfter the +50 write
    Simulator 18.211 more scroll event, momentum stopped
    Simulator 26.521 more scroll event, momentum stopped
    Simulator 27.03103–115 more events, 591–651px further
    iPhone 16 Pro, 27.0.13137–155 more events, 1876–2551px further

    A 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

    ClaimUnit probeReal iOS Safari
    Correction replayed after the gesture carried the viewport above the resized rowrow 20 shifted −50, want 0✅ 26.5: row 58 resized at 3095, reverse flick settles at 549, flush writes 599. 18.2: settles at 886, flush writes 936. iPhone 27.0.1: row 37 resized, momentum ends at the top of the list, flush writes 0 → 50
    cancelScroll before the retarget write loses the resize (#1305 gap)1000, want 1050✅ 26.5 + 18.2, but only when called in the same task as the measurement. One setTimeout(0) or rAF later, reconcile has already written and it lands correctly
    scrollBy replacing an in-flight index scroll drops the correction1100, want 1150✅ same window as above
    Safety valve loses the resize1000, want 1050not measured. Its precondition is real though: after a scrollToIndex under a finger the state was still alive when logging stopped, up to 3.7s later
    Gesture before the retarget write loses the resizerow 20 at +40, want −10not reproduced as written (one-frame window after landing). A scrollToIndex during momentum stops the momentum and lands normally. Under a finger it turns into the pull-back below
    Momentum baseline: resize above, momentum continues, one flush at settle3050✅ simulators and iPhone: deferred 50, 100+ more scroll events, flush 150ms after the last one

    Worth 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 scrollBy follows it. So the gap is "something ends the index scroll between a measurement and the next rAF".

    Needs correcting in the issue

    1. dropScrollState is not on main. #1306 was closed unmerged; the three exits are still this.scrollState = null. The "#1306" table row and the "prepend + resize + gesture … #1306's at-target guard" item describe code that never landed.
    2. The stale-scrollOffset item is not iOS-specific and is worse than described. If a row measures between the scrollToIndex write 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 a measureElement in that window (15050 instead of 5000). With natural ordering it lands correctly on iOS and Chromium, though I did see one resizeItem fall inside the window on iOS when scrollToIndex was called from a scroll handler. On iOS the #1305 drop hides it while isScrolling is true. I'd track it separately.
    3. "A drag before the target is reached pulls the user back" is real on device, and has a cause the issue doesn't mention. iOS Safari ignores a scrollTop write 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, hasReachedTarget stays 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 smooth scrollToIndex (26.5) behaves the same way: the touch stops the animation, no write follows, the state stays alive.
    4. Acceptance bullet 1. Six of the seven iOS deferral: tests on main assert the private _iosDeferredAdjustment value, so they cannot survive removing it unchanged. The tests from #1306 are not in the tree.

    On the proposal

    1. The anchor still needs history under momentum. Between capture and flush the viewport is supposed to move. "Return the row to the same place" taken literally undoes the user's scroll (in the baseline above, the capture-time row is 2000px away at settle). Storing the capture offset to subtract travel brings back "which offset was it classified against", and still gets the reverse-flick case wrong.
    2. It changes which resizes are compensated, on iOS only. Today a backward-scroll re-measure defers nothing (forward: 20), a custom shouldAdjustScrollPositionOnItemSizeChange returning 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.fails for 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.

  2. 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.userAgent on the device and the simulators, that would settle it.

    Corrections: agreed on all four. I'll update the issue: dropScrollState was #1306 only (closed), the stale-scrollOffset bug 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 on main or 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-measureElement repro 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.

  3. 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 against main (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 target

    I hit it in desktop Chromium through the Marko chat e2e while working on the stale-scrollOffset fix: extra size corrections during the initial scrollToEnd kept 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. main doesn'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.

  4. phcorp(GitHub profile, opens in a new tab)commented

    User agent on 27: the OS token is frozen, Version/ is not. Safari, one load each:

    OS token in the UAVersion/navigator.platform
    iPhone simulator 18.2iPhone OS 18_218.2iPhone
    iPhone simulator 26.5iPhone OS 18_726.5iPhone
    iPhone simulator 27.0iPhone OS 18_727.0iPhone
    iPhone 16 Pro, 27.0.1iPhone OS 18_727.0.1iPhone
    iPad simulator 18.2Intel Mac OS X 10_15_718.2MacIntel
    iPad simulator 26.5Intel Mac OS X 10_15_726.5MacIntel
    iPad simulator 27.0Intel Mac OS X 10_15_727.0MacIntel

    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.1

    So iPhone OS x_y cannot tell 26 from 27, and on iPad it never carried an iOS version. /Version\/(\d+)/ gives the real major on all seven. navigator.userAgentData is 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, scrollTop 2600 where the resize of row 5 alone would give 1050. I added it as a test.fails next to the finger-down one.

    PR: #1308 has the tests and the ios-deferral e2e 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), and chat.spec.ts:73 times out in the full e2e run on my machine, on main as well in 1 of 3 runs. Details are in the PR description.

  5. phcorp(GitHub profile, opens in a new tab)commented

    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.supports on 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.226.527.0
    overflow-anchor: autofalsefalsetrue
    width: stretchfalsefalsetrue
    appearance: base-selectfalsefalsetrue
    selector(::checkmark)falsefalsetrue
    selector(::picker(select))falsefalsetrue
    selector(:heading)falsefalsetrue
    Element.prototype.ariaNotifyfalsefalsetrue
    WebAssembly.Suspendingfalsefalsetrue
    shape-outside: shape(from 0 0, line to 1px 1px)falsetruefalse

    Why overflow-anchor over Version/:

    • 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 with Version/ >= 27 as 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.

  6. piecyk changed the title

  7. @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)

  8. phcorp(GitHub profile, opens in a new tab)commented

    @piecyk I went through the three PRs. Details are on each; the short version:

    PRResult
    #1309The fix works in Chromium, Firefox and WebKit. One regression: scrollBy gets stuck at the top and bottom edge, because a write that does not move the element never clears _lastWrittenOffset. Clamping the scrollBy target fixes it.
    #1310The fix works in the three browsers, and no regression found. It also removes the chat.spec.ts flake in Chromium. Two questions on the PR: a custom animated scrollToFn, and a clamped read-back with the target below the new max.
    #1311No behaviour difference from #1310 in 55,000 random event sequences, with every phase and transition reached.

    How I checked. Unit suites on main and 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 on virtual-core in 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:

    TestBrowsermain#1309#1310#1311
    chat › keeps visible messages stable when history is prependedChromium18194040
    chat › does not follow appended messages while reading historyChromium29374040
    smooth-prepend › a prepend mid-flight does not abandon a smooth scrollToIndexWebKit26242834
    smooth-scroll › index 500, start alignmentWebKit23213125
    smooth-scroll › index 500, center alignmentWebKit33353332
    • 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-prepend goes to 19, 18, 20, 20, so that one is load. "index 500, start" still fails 20–30% everywhere including main (16, 14, 15, 16 of 20), landing 4–128px off on main. 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 scrollToIndex can settle off its target on main and 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 on main and #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 main and 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.

  9. Plan update

    Status after the first round, and what changed in the plan.

    StepStatus
    1. Stale scrollOffset before 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
    touchcancel handled like touchend (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 scrollsready 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:

    • pendingWrite for a write until its read-back (replaces _intendedScrollOffset, ScrollState.writtenOffset, the stored scrollAdjustments);
    • _iosTouch (down / tail owning its timer) and one _iosInMotion() check (replaces three flags and three copies of the gate);
    • the pending prepend anchor as a tagged record;
    • _startScroll as 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 scrollToIndex with 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() drops isScrolling: only a touch defers (fixes #1250).
    • A scroll event while _iosTouch is in its tail re-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.ts converge; four of @phcorp's #1308 test.fails pass (a gesture, cancelScroll, the safety valve, and scrollBy each 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 #1308 ios-deferral page. 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 scrollOffset the way applyScrollAdjustment already does, so scrollAdjustments is always 0 and stays only as a getter for the documented custom predicate. Both replace _iosDeferredAdjustment code, 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

    scrollOffset as browser truth only, with an effective offset derived from the pending write. It would remove the eager folds and the remaining scrollAdjustments terms, but it changes what the public scrollOffset means mid-prepend.

    Open findings, not scheduled

    • An end-aligned scrollToIndex can settle off its target when corrections above and inside the viewport cancel out (21px in @phcorp's model; on main and 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 .fails test in #1310, not seen in a browser.
    • A custom scrollToFn that animates (the smooth-scroll example) ends an index scroll on its first frame; out of scope until scrollToFn can say it animates.
    • A resize before a scrollBy's read-back is not added to the relative target (CodeRabbit on #1309); scrollBy lands where it was written, better than 3.19.0.
  10. Open findings from @phcorp's simulator run on #1318 (also on main)

    • A row removed mid-touch leaves the touch down: touchend fires on the detached node and never reaches the scroll element, so the deferral stays on until the next touch. Possible fix: also listen for touchend/touchcancel on 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.
  11. 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 scrollTop can'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() and getTotalSize() 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:

    1. 2b, #1318: after #1317 (3.19.3) is released.
    2. Step 5's hold, #1319: stacked on #1318; its description lists what's left before it leaves draft.
    3. 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.
    4. 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.fails still fails with #1319.
    5. The rest of step 5: the scrollToOffset / scrollBy stall, and the anchor sync from a stale offset before an index scroll's read-back.
    6. Then a note on #884, asking for a retest on a version with all of the above.
  12. Status update: 2b merged, step 5's hold ready for review

    StepStatus
    1, 2, 2a, 2c/2dmerged and released (#1309, #1310, #1311, #1316)
    touchcancel like touchend#1314, released
    2b. Defer only for touch-driven scrolls#1318 merged, to be released on its own
    5. Hold a correction while scrollTop can't be written (#1287)#1319 ready for review
    3. iOS 27 momentumnext
    4. Per-row recordafter step 3, still a decision
    Rest of step 5after 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 down touch now records dragged, 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 calling stopPropagation() 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. scrollOffset keeps 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.fails still needs it) → the rest of step 5 (the scrollToOffset / scrollBy stall, 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-aligned scrollToIndex settling short (model only); the clamped read-back below a shrunk target (test.fails).

  13. @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:
      • scrollToIndex mid-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') is true.
      • Native anchoring: turn corrections off with virtualizer.shouldAdjustScrollPositionOnItemSizeChange = () => false, grow a row above the viewport while at rest, and check that scrollTop doesn'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') is false, and scrollToIndex mid-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.

  14. 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

    NameWhat it holdsFrom
    scrollOffset / scrollDirection / isScrollingScroll position in layout coordinates, direction, and whether the user is scrollingmain
    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 scrollmain
    pendingScrollAnchorWhat setOptions decided 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, null otherwisemain
    └ 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 rowmain
    _isIOSResultCached result of the "is this iOS WebKit?" checkmain
    _iosMomentumOverridesWritesResultCached iOS 27 gate: CSS.supports('overflow-anchor: auto') on iOS#1324

    Derived checks (computed when needed, no stored state)

    NameAnswersFrom
    scrollAdjustmentsCompensation written but not yet reported back (pendingWrite.adjustments)main
    getCommandWrittenOffset()Where the current command's unreported write put the elementmain
    _iosInMotion() / _iosDragging()A touch gesture owns the scroll / a finger is dragging, so iOS ignores writesmain
    _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

    NameDoesFrom
    _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 timermain
    _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 grownmain

    Net change against main

    • #1319: _holdOffset replaces _iosDeferredAdjustment, and _reportedOverscroll is added, so +1 stored value.
    • #1324: awaitingTail and tail.momentum are 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, awaitingTail and isClampedReadBack are the two worth questioning most: each fixes one specific case, the iOS 27 command mid-fling and #1310's clamped write.

  15. piecykcommented

    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's delta, _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.
    • scrollAdjustments is effectively always 0: applyScrollAdjustment adds it into scrollOffset and 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

    1. How far is the layout position ahead of the element?
    2. Who owns the scroll right now: the user, a command, or nobody?
    3. Can a write land right now?
    4. 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.snap stays byte-identical.

    • P1: one _classifyScrollEvent() returning 'spurious' | 'readBack' | 'clampedReadBack' | 'clampedEcho' | 'external', replacing the scattered checks in the scroll handler
    • P2: scrollState.awaitingTail becomes a queued phase of ScrollPhase (the command stores its behavior)
    • P3: _iosTouch's dragged and tail.momentum merge into one moved flag
    • P4: remove the internal adjustments plumbing (pendingWrite.adjustments, + this.scrollAdjustments at 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 pendingScrollAnchor only keeps follow. 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, pendingWrite read-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.

    Order: merge #1319 → merge #1324 → P1–P4 → decide on P5.

  16. 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 IosGesture class, stacked on #1324.

    Proof that the refactor changes no behaviour: scroll-trace.test.ts.snap stayed byte-identical after every refactor commit (27 traces × 60 seeds, web / iOS / iOS 27), and pnpm run test:pr is green.

    The plan, ticked off

    • P1: classifyScrollEvent() → 'spurious' | 'readBack' | 'clampedReadBack' | 'clampedEcho' | 'external', a pure function in src/scroll-classifier.ts with a truth-table test, run once before the handler writes any state
    • P2: awaitingTail → a queued phase; the command stores its behavior
    • P3: dragged + momentum → one moved flag
    • P4: the internal adjustments plumbing is gone; scrollAdjustments is @deprecated and 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 scrollToFn that reports its write back synchronously. Without the guard, the correction lands twice.
    • The IosGesture class (#1325), with fake-timer unit tests.

    What we learned

    • scrollAdjustments really was 0 at every observable point while enabled. The only exception was enabled: 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's delta. 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.

  17. @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 scrollToOffset case (prepend held in setOptions), fixed in 3f725bd2.
    • #1325 pulls the iOS touch handling into an IosGesture class, no behaviour change.

    Heads-up, my state table from this morning is a bit stale now: awaitingTail became a queued phase, dragged and tail.momentum are a single moved flag, and the read-back checks live in classifyScrollEvent().

    If you get a chance, two things would help most:

    1. 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.
    2. The device checks in #1324: scrollToIndex mid-fling should land after the fling without a flash, and a drag while it waits should cancel it but a tap shouldn't.

    Thanks!

  18. @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

    CheckSim 27.0iPhone 27.0.1
    scrollToIndex mid-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 itfail 3/3fail 3/3
    a tap during the wait does not cancel itpass 3/3pass 2/3 (one run: the write showed one frame, then the command was dropped)
    a command at rest is immediatepass 3/3pass 1/1
    CSS.supports('overflow-anchor: auto')true in Safari and WKWebViewtrue in Safari
    native anchoring (corrections off, a row above grows at rest)pass 3/3: scrollTop stays, the row moves 50pxpass 1/1

    iOS 26.5: CSS.supports('overflow-anchor: auto') is false in Safari and WKWebView, and scrollToIndex mid-fling writes at once and lands (3/3), as on main. The WKWebView UA has no Version/ 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 window in 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 _iosTouch never 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, stopPropagation in 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.

  19. 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.

    c6188ae8 in #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.

  20. @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).

    CaseiPhone: Safari / Chrome / FirefoxSim 27.0
    fling left alonelands +150–152ms after the fling stops, 3/32/2
    drag back during the waitcancelled, 3/33/3
    second flickcancelled, 3/32/2
    tap while it still glides fastcancelled, 3/32/2
    tap near the end of the glidenot cancelled: the command lands, 3/32/2
    CSS.supports('overflow-anchor: auto')true in all threetrue

    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.
  21. Thanks @phcorp, both fixed in 75b04923 (#1324):

    • Late tap: flingCaught now 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.

  22. @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).

    CaseSim 27.0iPhone 27.0.1
    late tapcancelled 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 alonelands 3/3lands 2/2 (+152ms)
    late first frame, flick that scrolled before liftinglands 5/5not run
    late first frame, flick that lifted before any scroll eventlost 1/1: tail not reopened, written mid-fling, gone after 2 framesnot run

    The last row: the reopen is armed only when moved was 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 touchend listener, 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.

  23. 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 between touchstart and touchend as 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.

  24. The plan in this issue is complete. All steps are merged.

    StepPR
    1. Stale scrollOffset before 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 recordNot 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 scrollTop for 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.

  25. piecyk closed this

Sign in to join this conversation.