Skip to content
Source
Sign inSign up
TanStack/virtual

fix(virtual-core): record the committed max as a clamp candidate #1330

Mergedpiecykmerged 3 commits intomain fromrefs/pull/1330/headmerged by piecyk

Showing 6 changed files with 44 additions and 38 deletions (loading 2).

x
0 of 6 viewed, 6 left
7 additions and 0 deletions.changeset/clamped-commit-survives.mdAdded
View file
@@ -0,0 +1,7 @@
+---
+'@tanstack/virtual-core': patch
+---
+​
+fix(virtual-core): keep an instant scroll command clamped at a max the sizer committed outside a row resize
+​
+Before an instant scroll command's write is reported, the browser can clamp it at a smaller scroll max that the sizer moves to without a row resize: an append or prepend, `measure()`, or a resize the sizer had not committed when the command was written. The virtualizer now also records the max at each commit, so such an event is read as its own clamped write and the command lands. A clamped write reported with `isScrolling` false is now written again too.
31 additions and 32 deletionspackages/virtual-core/src/index.tsModified
View file
@@ -610,15 +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.
+ // - `lowMaxes`: for a command's instant write, each scroll max below
+ // `target` the element had since the write. A command's target is
+ // clamped to the max at the write, but the sizer can shrink under it
+ // before the report (rows measured smaller, a count change) and grow
+ // back, so the read-back is the max the browser clamped to then rather
+ // than the element's current one. Read wherever the sizer can have