Skip to content
Source
Sign inSign up
TanStack/virtual

fix(virtual-core): let a user scroll end a non-smooth scrollToIndex before it lands #1310

Mergedpiecykmerged 2 commits intomain fromrefs/pull/1310/headmerged by piecyk

Showing 3 changed files with 120 additions and 42 deletions.

x
0 of 3 viewed, 3 left
5 additions and 0 deletions.changeset/index-scroll-user-interrupt.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/virtual-core': patch
+---
+​
+fix(virtual-core): let a user scroll end a non-smooth `scrollToIndex` before reconcile has seen it land, so a later measurement no longer pulls the user back to the old target
26 additions and 4 deletionspackages/virtual-core/src/index.tsModified
View file
@@ -406,6 +406,10 @@
stableFrames: number
// Keep arrival across measurement-driven retargets so external scrolls can cancel.
hasReachedTarget: boolean
+ // The command asked for a smooth scroll. Unlike `behavior`, which reconcile
+ // switches to 'auto' for the final approach, this stays set: the smooth
+ // animation can still deliver scroll events after that switch.
+ startedSmooth: boolean
​
// Where our last non-smooth write for this command put the element, until
// its scroll event arrives. Until then `scrollOffset` still holds the old
@@ -969,15 +973,29 @@
offset = this._intendedScrollOffset
} else if (
this.scrollState?.index != null &&