refactor(virtual-core): extract the iOS touch gesture into IosGesture (#1307) #1325
main fromrefs/pull/1325/head·merged by piecyk 🎯 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.snapis byte-identical to #1324's head; core suite 365 passed (351 before plus 14 in the newios-gesture.test.ts).ios-gesture.test.tscovers 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 | nullfield with its own resets (0820407b). A new touch orend()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 newIosGesturetest fails on the old code. - A waiting command's fling samples live on the command (
sampleson thequeuedscroll state) instead of a virtualizer field reset by hand (c1e6d9a0). - Dead code dropped: the timer's
_touch === tailchecks and a cleanupend()that duplicated the listener unsubscribe's;inTail()+momentumOverridesWrites()are now onetail()query. - Snapshot unchanged after each commit; core suite 407 passed.
- 1
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.mdpackages/virtual-core/src/index.tspackages/virtual-core/src/ios-gesture.tspackages/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.tsThe 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.mdVirtualizer 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:
4 · 1-
Failed checks: 1 warningCheck name Status Explanation Resolution Docstring Coverage 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 … Write docstrings for the functions missing them to satisfy the coverage threshold. Passed checks: 4 passed-
Check name Status Explanation Title check The title clearly identifies the primary change: extracting the iOS touch gesture into the internal IosGesture class. It is concise and specific. Description check The description covers the change, motivation, implementation details, test evidence, risk, checklist, and release impact. It confirms the required checklist items and changeset. Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check 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.
Comment `@coderabbitai help` to get the list of available commands.-
View your CI Pipeline Execution ↗ for commit ceb05feb733b5eb40b54a472c1e2360416e6827a
Command Status Duration Result nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded 4m 15s View ↗ nx run-many --target=build --exclude=examples/**✅ Succeeded 14s View ↗
☁️ Nx Cloud last updated this comment at
2026-10-15 06:06:25UTCMore templates
- tanstack-lit-virtual-example-dynamic
- tanstack-lit-virtual-example-fixed
- @tanstack/virtual-example-angular-chat
- @tanstack/virtual-example-angular-dynamic
- @tanstack/virtual-example-angular-fixed
- @tanstack/virtual-example-angular-infinite-scroll
- @tanstack/virtual-example-angular-padding
- @tanstack/virtual-example-angular-smooth-scroll
- @tanstack/virtual-example-angular-sticky
- @tanstack/virtual-example-angular-table
- @tanstack/virtual-example-angular-variable
- @tanstack/virtual-example-angular-window
- tanstack-marko-virtual-example-chat
- tanstack-marko-virtual-example-chat-pretext
- tanstack-marko-virtual-example-dynamic
- tanstack-marko-virtual-example-fixed
- tanstack-marko-virtual-example-grid
- tanstack-marko-virtual-example-infinite-scroll
- tanstack-marko-virtual-example-padding
- tanstack-marko-virtual-example-pretext
- tanstack-marko-virtual-example-scroll-padding
- tanstack-marko-virtual-example-smooth-scroll
- tanstack-marko-virtual-example-ssr
- tanstack-marko-virtual-example-ssr-fetch
- tanstack-marko-virtual-example-ssr-restore
- tanstack-marko-virtual-example-ssr-slice
- tanstack-marko-virtual-example-sticky
- tanstack-marko-virtual-example-table
- tanstack-marko-virtual-example-variable
- tanstack-marko-virtual-example-window
- tanstack-marko-virtual-example-window-ssr-slice
- tanstack-react-virtual-example-chat
- tanstack-react-virtual-example-dynamic
- tanstack-react-virtual-example-fixed
- tanstack-react-virtual-example-infinite-scroll
- tanstack-react-virtual-example-padding
- tanstack-react-virtual-example-pretext
- tanstack-react-virtual-example-scroll-padding
- tanstack-react-virtual-example-smooth-scroll
- tanstack-react-virtual-example-sticky
- tanstack-react-virtual-example-table
- tanstack-react-virtual-example-variable
- tanstack-react-virtual-example-window
- tanstack-vue-virtual-example-dynamic
- tanstack-vue-virtual-example-fixed
- tanstack-vue-virtual-example-infinite-scroll
- tanstack-vue-virtual-example-padding
- tanstack-vue-virtual-example-scroll-padding
- tanstack-vue-virtual-example-smooth-scroll
- tanstack-vue-virtual-example-sticky
- tanstack-vue-virtual-example-table
- tanstack-vue-virtual-example-variable
- tanstack-svelte-virtual-example-dynamic
- tanstack-svelte-virtual-example-fixed
- tanstack-svelte-virtual-example-infinite-scroll
- tanstack-svelte-virtual-example-smooth-scroll
- tanstack-svelte-virtual-example-sticky
- tanstack-svelte-virtual-example-table
@tanstack/angular-virtual
npm i https://pkg.pr.new/@tanstack/angular-virtual@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@1325commit:
ceb05fepiecyk merged this77cb05e
piecyk closed this
Sign in to join this conversation.
🦋 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
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