You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add end-anchored virtualization support for chat, logs, and reverse feeds.
6
+
7
+
New `anchorTo: 'end'` mode keeps the current visible item stable when older items are prepended, while preserving the existing start-anchored behavior by default. It also keeps an end-pinned viewport pinned when the last item grows during streaming output.
8
+
9
+
Add `followOnAppend` so new items scroll into view only when the viewport was already at the end, plus `scrollEndThreshold`, `scrollToEnd()`, `getDistanceFromEnd()`, and `isAtEnd()` helpers for chat-style integrations.
Copy file name to clipboardExpand all lines: docs/api/virtualizer.md
+64Lines changed: 64 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -245,6 +245,42 @@ Controls when lane assignments are cached in a masonry layout.
245
245
-`'estimate'` (default): lane assignments are cached immediately based on `estimateSize`. This keeps items from jumping between lanes, but assignments may be suboptimal when the estimate is inaccurate.
246
246
-`'measured'`: lane caching is deferred until items are measured via `measureElement`, so assignments reflect actual measured sizes. After the initial measurement, lanes are cached and remain stable.
247
247
248
+
### `anchorTo`
249
+
250
+
```tsx
251
+
anchorTo?:'start'|'end'
252
+
```
253
+
254
+
**Default:**`'start'`
255
+
256
+
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.
257
+
258
+
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.
259
+
260
+
For prepend stability, use a stable `getItemKey` based on each item's persistent id. Index keys cannot distinguish prepends from appends after items shift.
261
+
262
+
### `followOnAppend`
263
+
264
+
```tsx
265
+
followOnAppend?:boolean|'auto'|'smooth'|'instant'
266
+
```
267
+
268
+
**Default:**`false`
269
+
270
+
When used with `anchorTo: 'end'`, controls whether the virtualizer scrolls to the end after new items are appended. The follow only happens if the viewport was already at the end before the append; users who have scrolled up to read history are not pulled down.
271
+
272
+
Passing `true` is equivalent to `'auto'`. Passing a scroll behavior uses that behavior for the follow.
273
+
274
+
### `scrollEndThreshold`
275
+
276
+
```tsx
277
+
scrollEndThreshold?:number
278
+
```
279
+
280
+
**Default:**`1`
281
+
282
+
The pixel threshold used by `isAtEnd()` and `followOnAppend` to decide whether the viewport is close enough to the end to count as pinned.
283
+
248
284
### `isScrollingResetDelay`
249
285
250
286
```tsx
@@ -389,6 +425,34 @@ scrollBy: (
389
425
390
426
Scrolls the virtualizer by the specified number of pixels relative to the current scroll position.
391
427
428
+
### `scrollToEnd`
429
+
430
+
```tsx
431
+
scrollToEnd: (
432
+
options?: {
433
+
behavior?:'auto'|'smooth'|'instant'
434
+
}
435
+
) =>void
436
+
```
437
+
438
+
Scrolls the virtualizer to the end of the content. For vertical lists this is the bottom; for horizontal lists this is the right edge.
439
+
440
+
### `getDistanceFromEnd`
441
+
442
+
```tsx
443
+
getDistanceFromEnd: () =>number
444
+
```
445
+
446
+
Returns the current pixel distance from the end of the virtualized content.
447
+
448
+
### `isAtEnd`
449
+
450
+
```tsx
451
+
isAtEnd: (threshold?:number) =>boolean
452
+
```
453
+
454
+
Returns whether the viewport is within `threshold` pixels of the end. If no threshold is provided, `scrollEndThreshold` is used.
0 commit comments