Skip to content
Source
Sign inSign up
TanStack/virtual

fix(virtual-core): keep an instant scroll command through a transient clamp #1329

Mergedpiecykmerged 4 commits intomain fromrefs/pull/1329/headmerged by piecyk

Showing 5 changed files with 70 additions and 3 deletions (loading 2).

x
0 of 5 viewed, 5 left
7 additions and 0 deletions.changeset/clamped-end-survives.mdAdded
View file
@@ -0,0 +1,7 @@
+---
+'@tanstack/virtual-core': patch
+---
+​
+fix(virtual-core): keep an instant scroll command when the browser clamps its write before rows grow back
+​
+Rows measured right after an instant `scrollToEnd()` (or `scrollToIndex`) can first shrink the sizer below the written position and then grow it again in the same task. The browser clamps the write to the smaller max, and the scroll event reports that position. It was read as the user scrolling away, so the command was cancelled and the list stopped short of the end (a chat opened with `estimateSize` larger than its rows). The virtualizer now follows the scroll max through those measurements and reads such an event as its own clamped write, so the command retargets and lands at the end.
41 additions and 0 deletionspackages/virtual-core/src/index.tsModified
View file
@@ -610,9 +610,16 @@
// further by the time it reports.
// - `smooth`: the write animates, so until it lands the element is
// somewhere between the old offset and `target`.
+ // - `max`, `lowMaxes`: for a command's instant write, the scroll max as
+ // rows measured since the write moved it (`resizeItem`), and each value
+ // it took below `target`. The browser clamps the write to one of them
+ // at a layout, and the sizer can grow back before the report, so the
+ // read-back is that max rather than the element's current one.
private pendingWrite: {
target: number
smooth: boolean
+ max?: number
+ lowMaxes?: Array<number>
} | null = null