Skip to content
Source
Sign inSign up
TanStack/virtual

fix(virtual-core): keep an end-pinned viewport pinned when the scroll element shrinks #1298

Openlangleyd(GitHub profile, opens in a new tab)wants to merge 2 commits intomain fromrefs/pull/1298/headopened

Showing 7 changed files with 7 additions and 2 deletions (loading 4).

x
0 of 7 viewed, 7 left
5 additions and 0 deletions.changeset/end-anchor-scroll-element-resize.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/virtual-core': patch
+---
+​
+With `anchorTo: 'end'`, keep an end-pinned viewport pinned when the scroll element shrinks, for example when the window is resized or the app changes its height. Previously the browser kept `scrollTop`, leaving the last items below the fold.
1 addition and 1 deletiondocs/api/virtualizer.mdModified
View file
@@ -255,7 +255,7 @@
​
Controls which side of the scrollable content should be treated as the stable anchor when list data changes. The default `'start'` preserves TanStack Virtual's existing top/left anchored behavior.
​
-Set `anchorTo: 'end'` for chat, logs, and reverse/inverted feeds. In end-anchored mode, the virtualizer keeps the current visible item stable when older items are prepended, and keeps an end-pinned viewport pinned when the last item grows during streaming output. See the [Chat guide](../chat) for the full pattern.
+Set `anchorTo: 'end'` for chat, logs, and reverse/inverted feeds. In end-anchored mode, the virtualizer keeps the current visible item stable when older items are prepended, and keeps an end-pinned viewport pinned when the last item grows during streaming output or the scroll element shrinks. See the [Chat guide](../chat) for the full pattern.
​
For prepend stability, use a stable `getItemKey` based on each item's persistent id. Index keys cannot distinguish prepends from appends after items shift.
​
1 addition and 1 deletiondocs/chat.mdModified
View file
@@ -73,7 +73,7 @@
​
### Keep streaming output pinned
​
-Streaming chat responses usually grow the last item many times. In end-anchored mode, if the viewport is pinned to the end before the measured size changes, the virtualizer adjusts by the size delta and keeps the bottom stuck to the latest output.
+Streaming chat responses usually grow the last item many times. In end-anchored mode, if the viewport is pinned to the end before the measured size changes, the virtualizer adjusts by the size delta and keeps the bottom stuck to the latest output. The same applies when the scroll element shrinks, for example when the window is resized or the app changes its height.
​
This works with the normal dynamic measurement pattern:
​