Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/clamp-range-scroll-offset.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/virtual-core': patch
---

Keep a full viewport of rows in the range when the scroll offset is past the end of the list, as it is after the list shrinks and before the element reports its clamped position.
11 changes: 9 additions & 2 deletions packages/virtual-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1860,16 +1860,23 @@ export class Virtualizer<
this.getSize(),
this.getScrollOffset(),
this.options.lanes,
// scrollOffset is measured in the scroll element and the layout total
// from the list start, so the list ends scrollMargin further down.
this._getLayoutTotalSize() + this.options.scrollMargin,
],
(measurements, outerSize, scrollOffset, lanes) => {
(measurements, outerSize, scrollOffset, lanes, listEnd) => {
if (measurements.length === 0 || outerSize === 0) {
this.range = null
return null
}
// Until the element reports a clamped position (the list shrank, a
// rubber-band bounce), the offset can sit past the last row, which
// would leave only that row in the range.
const maxScrollOffset = Math.max(listEnd - outerSize, 0)
this.range = calculateRangeImpl(
measurements,
outerSize,
scrollOffset,
Math.min(scrollOffset, maxScrollOffset),
lanes,
// Pass the typed array so binary search + forward-walk can read
// start/end directly from Float64Array, skipping the Proxy traps.
Expand Down
Loading
Loading