feat(virtual-core): add cancelScroll() to stop an in-flight scroll reconciliation #1300
main fromrefs/pull/1300/head·merged by piecyk 🎯 Changes#
Closes #1285.
After scrollToIndex / scrollToOffset / scrollBy / scrollToEnd, reconcileScroll keeps correcting toward the target for up to 5s. If the user scrolls during that window, any measurement that moves the target pulls the viewport back. During a smooth scroll, size-change compensation is also off until the scroll finishes or times out. Until now, the only way out was writing the private scrollState field.
scrollToIndex(i)
scrollState = { index: i, ... }
_scrollToOffset(target)
scheduleScrollReconcile() // rAF loop, ≤ 5s
+
+cancelScroll()
+ cancelAnimationFrame(rafId)
+ scrollState = null // scroll position untouched
The scroll position is deliberately left as it is. Writing it would stop iOS momentum, and a real gesture already interrupts a native smooth scroll. The app decides when the user has taken over, for example from wheel / touchstart / keydown handlers. Detecting that automatically in core is left for a follow-up.
packages/
├── virtual-core/src/index.ts + cancelScroll()
├── angular-virtual/src/index.ts + 'cancelScroll' in the signal proxy's pass-through list
└── marko-virtual/src/tags/
├── virtualizer/index.marko + cancelScroll on the handle
└── window-virtualizer/index.marko + cancelScroll on the handle
React, Vue, Solid, Svelte and Lit return the core instance, so they get it without changes. Docs: api/virtualizer.md, the chat guide's API list, and the Marko docs and README tables.
Evidence#
New core tests in packages/virtual-core/tests/index.test.ts:
scrollToIndex(50) → cancelScroll() → resizeItem(10, 200) → flush rAF
expect scrollToFn not called again // no yank toward the moved target
scrollOffset = 1000 → scrollToIndex(50, smooth) → cancelScroll() → resizeItem(0, 80)
expect scrollToFn(1000, { adjustments: 30 }) // compensation is back
cancelScroll() with nothing in flight → no-op; later scrollToOffset still settles
- Before (
cancelScrollstubbed toreturn): the first two tests fail. - After: all 3 pass. virtual-core: 174 tests pass.
pnpm run test:pr --base=upstream/mainpasses for 69 projects.
Merge Danger#
Door: two-way. The new method only runs when called. Adding a public method can't be undone without a major release, though, so the name is worth agreeing on now (cancelScroll, since it also covers scrollBy / scrollToEnd).
Blast Radius: none. Nothing calls it internally, so existing behaviour is unchanged.
#1294 also changes reconcileScroll. The two don't conflict in purpose, but whichever merges second needs a small rebase.
✅ 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#
- New Features
- Added
cancelScroll()to stop an in-progress virtualized scroll without changing the current position. Available across the core, Angular, and Marko APIs.
- Added
- Documentation
- Added
cancelScroll()to the API references.
- Added
- 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:
1c47744a-2e37-4ca8-a288-cb623b3f5e21
📥 Commits
Reviewing files that changed from the base of the PR and between c644f1096c9f4d8221d92862afdc9316b17df62a and 88129a9681a203b2df96b9d0d5785a38786ecb4f.
📒 Files selected for processing (10)
.changeset/cancel-scroll.mddocs/api/virtualizer.mddocs/chat.mddocs/framework/marko/marko-virtual.mdpackages/angular-virtual/src/index.tspackages/marko-virtual/README.mdpackages/marko-virtual/src/tags/virtualizer/index.markopackages/marko-virtual/src/tags/window-virtualizer/index.markopackages/virtual-core/src/index.tspackages/virtual-core/tests/index.test.ts
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
Walkthrough#
Adds
cancelScroll()to virtual-core to stop active scroll reconciliation without changing the current scroll position. Angular and Marko APIs expose the method. Tests cover cancellation behavior, and documentation and release notes describe the API.Changes#
Scroll cancellation
Layer / File(s) Summary Core cancellation and tests
packages/virtual-core/src/index.ts,packages/virtual-core/tests/index.test.tsVirtualizer.cancelScroll()cancels a scheduled animation frame and clearsscrollState. Tests cover indexed and smooth scroll cancellation, cancellation with no active scroll, and subsequent offset scrolling.Framework API exposure
packages/angular-virtual/src/index.ts,packages/marko-virtual/src/tags/virtualizer/index.marko,packages/marko-virtual/src/tags/window-virtualizer/index.markoThe Angular proxy passes through cancelScroll. Marko virtualizer handles declare the method and delegate it to the active virtualizer.API documentation and release note
docs/api/virtualizer.md,docs/chat.md,docs/framework/marko/marko-virtual.md,packages/marko-virtual/README.md,.changeset/cancel-scroll.mdThe documentation describes cancelScroll()and its behavior. The changeset declares minor releases for the virtual-core, Angular, and Marko packages.Priority: ➖ Normal
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Feature · Severity of issue fixed: Medium
Merge Risk: ⚪ Minimal · up to
88129This adds an optional
cancelScroll()method to stop in-flight scroll reconciliation without moving the current scroll position. Existing behavior is unchanged unless callers use the new method, so the merge risk is minimal.🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
Check 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 3 files. (7 skipped: 7 … 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 main change: adding cancelScroll() to stop in-flight scroll reconciliation. Description check The description is complete and relevant. It explains the motivation, implementation, affected packages, tests, release impact, and checklist status. It also documents compatibility considerations and… Linked Issues check Issue #1285requires a public core API that cancels active scroll reconciliation for index and offset scrolling without changing the current DOM offset, and preserves later measurement compensation. T…Out of Scope Changes check The changes stay within Issue #1285. The core method, adapter exposure, documentation, changeset, and focused tests support the public cancellation API. Extending the documented method toscrollBya…
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 3 files. (7 skipped: 7 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/index.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/index.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 88129a9681a203b2df96b9d0d5785a38786ecb4f
Command Status Duration Result nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded 4m 2s View ↗ nx run-many --target=build --exclude=examples/**✅ Succeeded 21s View ↗
☁️ Nx Cloud last updated this comment at
2026-10-09 12:16:32UTCMore templates
- @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-lit-virtual-example-dynamic
- tanstack-lit-virtual-example-fixed
- 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-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-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/angular-virtual
npm i https://pkg.pr.new/@tanstack/angular-virtual@1300@tanstack/lit-virtual
npm i https://pkg.pr.new/@tanstack/lit-virtual@1300@tanstack/marko-virtual
npm i https://pkg.pr.new/@tanstack/marko-virtual@1300@tanstack/react-virtual
npm i https://pkg.pr.new/@tanstack/react-virtual@1300@tanstack/solid-virtual
npm i https://pkg.pr.new/@tanstack/solid-virtual@1300@tanstack/svelte-virtual
npm i https://pkg.pr.new/@tanstack/svelte-virtual@1300@tanstack/virtual-core
npm i https://pkg.pr.new/@tanstack/virtual-core@1300@tanstack/vue-virtual
npm i https://pkg.pr.new/@tanstack/vue-virtual@1300commit:
88129a9piecyk merged this43675bc
piecyk closed this
Sign in to join this conversation.
🦋 Changeset detected#
Latest commit: 88129a9681a203b2df96b9d0d5785a38786ecb4f
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