Skip to content
Source
Sign inSign up
TanStack/virtual

refactor(virtual-core): extract the iOS touch gesture into IosGesture (#1307) #1325

Mergedpiecykmerged 5 commits intomain fromrefs/pull/1325/headmerged by piecyk

piecykcommented

🎯 Changes

Follows #1324 (merged); rebased onto main.

Follow-up to the scroll-state refactor planned in #1307: the iOS touch gesture moves out of the virtualizer into a small class in an internal module. No behaviour change, except one small fix (below).

Summary

 src/
 ├── index.ts              # Virtualizer
-│     _iosTouch, _openIosTail, _endIosTouch, _iosInMotion, _iosDragging,
-│     touch listeners, isIOSWebKit, iosMomentumOverridesWrites
+│     _iosGesture = new IosGesture({ getWindow, now, tailStillMoving, onTailClosed })
+├── ios-gesture.ts        # IosGesture + iOS detection
 └── scroll-classifier.ts
IosGesture
  state        null | down{moved} | tail{moved, awaitingFling} | lateFling{until}
  queries      inMotion()  dragging()  tail() → 'tap' | 'fling' | null
  events       touchStart()  touchEnd()  listen(scrollElement) → unsubscribe
  from onScroll  onScroll({ isScrolling, ownReadBack, moved, external }) → finger is dragging
               // also reopens a tail whose fling's first frame came late (within 1s of a drag)
  lifecycle    end()   // drops any state, and with it the tail timer
  host         getWindow()        // the scroll element's window runs the timer
               now()              // clock for the late-fling window
               tailStillMoving()  // virtualizer: the element moved with no scroll event, keep the tail open
               onTailClosed()     // virtualizer: cancel a caught queued command, flush the hold, then write it

The scroll handler reports each event through onScroll; when it returns true and a command is queued, the command is cancelled (the same condition as before). Detaching the listeners still ends the gesture, and cleanup() still ends it while a window is set. _resetIOSDetectionForTests is re-exported from index.ts, so test imports are unchanged.

Evidence

  • scroll-trace.test.ts.snap is byte-identical to #1324's head; core suite 365 passed (351 before plus 14 in the new ios-gesture.test.ts).
  • ios-gesture.test.ts covers the class alone with fake timers: tap, drag, tail re-arm, timer cancel and restart, non-iOS and no window, the iOS 27 gate, and listener attach/detach order with capture/passive options.
  • Existing tests that read the gesture now go through _iosGesture.touch / .dragging(): 45 mechanical renames, no assertion changed.

Merge Danger

Door: two-way

Blast Radius: iOS scrolling

Internal move only. A mistake would show as a missed or early tail close on iOS (a correction or a queued command written mid-fling, or held too long); the snapshot's ios and ios27 platforms cover those orderings.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved scroll handling on iOS during touch gestures and momentum scrolling, helping keep scroll adjustments and commands in sync with user movement.
    • Prevented pending momentum scrolling from affecting a different scroll element after it changes.

After an Opus review

  • The late-fling window is a phase of the gesture (lateFling { until }), not a second 'awaiting' | deadline | null field with its own resets (0820407b). A new touch or end() replaces it, so the old "no finger down" guard is now structural. inMotion() does not count it: it defers nothing.
  • Fix: end() (cleanup, scroll-element swap) now drops a pending late-fling window. Before, it survived, and a scroll on the new element within 1s could open a stray 150ms tail. A new IosGesture test fails on the old code.
  • A waiting command's fling samples live on the command (samples on the queued scroll state) instead of a virtualizer field reset by hand (c1e6d9a0).
  • Dead code dropped: the timer's _touch === tail checks and a cleanup end() that duplicated the listener unsubscribe's; inTail() + momentumOverridesWrites() are now one tail() query.
  • Snapshot unchanged after each commit; core suite 407 passed.
    1. changeset-bot[bot](GitHub profile, opens in a new tab)commented

      🦋 Changeset detected

      Latest commit: ceb05feb733b5eb40b54a472c1e2360416e6827a

      The changes in this PR will be included in the next version bump.

      This PR includes changesets to release 9 packages
      NameType
      @tanstack/virtual-corePatch
      @tanstack/angular-virtualPatch
      @tanstack/lit-virtualPatch
      @tanstack/marko-virtualPatch
      @tanstack/react-virtualPatch
      @tanstack/solid-virtualPatch
      @tanstack/svelte-virtualPatch
      @tanstack/vue-virtualPatch
      @tanstack/virtual-benchmarksPatch

      Not sure what this means? Click here to learn what changesets are.

      Click here if you're a maintainer who wants to add another changeset to this PR

    2. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration
      • Configuration used: defaults
      • Review profile: CHILL
      • Plan: Advanced
      • Run ID: 23473385-2a8a-4e49-a63a-b8af0ebecf6b
      📥 Commits

      Reviewing files that changed from the base of the PR and between b3528f18eabd612c5f6477dcb136a1996cccc24d and ceb05feb733b5eb40b54a472c1e2360416e6827a.

      📒 Files selected for processing: 4
      • .changeset/ios-gesture.md
      • packages/virtual-core/src/index.ts
      • packages/virtual-core/src/ios-gesture.ts
      • packages/virtual-core/tests/ios-gesture.test.ts
      🚧 Files skipped from review as they are similar to previous changes: 1
      • .changeset/ios-gesture.md

      Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

      📝 Walkthrough

      iOS touch gesture tracking moves from inline Virtualizer logic into ios-gesture.ts. Virtualizer delegates gesture state and listener handling to the new module. Queued commands track recent scroll samples and can be canceled when scroll direction reverses or acceleration is detected. Tests cover the tracker and update integration checks.

      Changes: iOS Gesture Tracking

      Layer / File(s)Summary
      Gesture detection and lifecycle
      packages/virtual-core/src/ios-gesture.ts, packages/virtual-core/tests/ios-gesture.test.ts
      The new module detects iOS WebKit and tracks touch, drag, and momentum-tail state, including a late-fling window. Tests cover detection, state transitions, timers, and listener cleanup.
      Virtualizer integration and command handling
      packages/virtual-core/src/index.ts, packages/virtual-core/tests/index.test.ts, .changeset/ios-gesture.md
      Virtualizer delegates touch and scroll tracking to IosGesture. Queued commands retain recent scroll samples and are canceled on direction reversal or detected acceleration. Integration tests inspect the tracker, and the Changeset records a patch release.

      Priority: ➖ Normal

      Estimated code review effort: 3 (Moderate) | ~20 minutes

      Change: Refactor

      Merge Risk: ⚪ Minimal · up to ceb05

      No actionable issue is established; the change is mergeable after normal checks.

      Pre-merge checks: Passed 4 · Failed 1
      Failed Failed checks: 1 warning
      Check nameStatusExplanationResolution
      Docstring CoverageWarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 4 files. (1 skipped: 1 …Write docstrings for the functions missing them to satisfy the coverage threshold.
      Passed Passed checks: 4 passed
      Check nameStatusExplanation
      Title checkPassedThe title clearly identifies the primary change: extracting the iOS touch gesture into the internal IosGesture class. It is concise and specific.
      Description checkPassedThe description covers the change, motivation, implementation details, test evidence, risk, checklist, and release impact. It confirms the required checklist items and changeset.
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Full details: Docstring Coverage

      Explanation

      Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 4 files. (1 skipped: 1 unsupported.)

      • Fix all pre-merge checks with AI
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      Warning

      Some tools did not complete. Review the errors below.

      🔧 ESLint

      If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

      packages/virtual-core/tests/ios-gesture.test.ts

      Parsing error: "parserOptions.project" has been provided for @typescript-eslint/parser. The file was not found in any of the provided project(s): packages/virtual-core/tests/ios-gesture.test.ts

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.
    3. nx-cloud[bot](GitHub profile, opens in a new tab)commented

      View your CI Pipeline Execution ↗ for commit ceb05feb733b5eb40b54a472c1e2360416e6827a

      CommandStatusDurationResult
      nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded4m 15sView ↗
      nx run-many --target=build --exclude=examples/**✅ Succeeded14sView ↗

      ☁️ Nx Cloud last updated this comment at 2026-10-15 06:06:25 UTC

    4. pkg-pr-new[bot](GitHub profile, opens in a new tab)commented
      More templates

      @tanstack/angular-virtual

      npm i https://pkg.pr.new/@tanstack/angular-virtual@1325

      @tanstack/lit-virtual

      npm i https://pkg.pr.new/@tanstack/lit-virtual@1325

      @tanstack/marko-virtual

      npm i https://pkg.pr.new/@tanstack/marko-virtual@1325

      @tanstack/react-virtual

      npm i https://pkg.pr.new/@tanstack/react-virtual@1325

      @tanstack/solid-virtual

      npm i https://pkg.pr.new/@tanstack/solid-virtual@1325

      @tanstack/svelte-virtual

      npm i https://pkg.pr.new/@tanstack/svelte-virtual@1325

      @tanstack/virtual-core

      npm i https://pkg.pr.new/@tanstack/virtual-core@1325

      @tanstack/vue-virtual

      npm i https://pkg.pr.new/@tanstack/vue-virtual@1325

      commit: ceb05fe

    5. piecyk merged this77cb05e

    6. piecyk closed this

Sign in to join this conversation.