@tanstack/virtual-core 3.19.9 → 3.19.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/virtual-core",
3
- "version": "3.19.9",
3
+ "version": "3.19.11",
4
4
  "description": "Headless UI for virtualizing scrollable elements in TS/JS + Frameworks",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
package/src/index.ts CHANGED
@@ -300,16 +300,29 @@ export const measureElement = <TItemElement extends Element>(
300
300
  ]
301
301
  }
302
302
 
303
- const scrollWithAdjustments = (
303
+ const scrollWithAdjustments = <
304
+ TScrollElement extends Element | Window,
305
+ TItemElement extends Element,
306
+ >(
304
307
  offset: number,
305
308
  {
306
309
  adjustments = 0,
307
310
  behavior,
308
311
  }: { adjustments?: number; behavior?: ScrollBehavior },
309
- instance: Virtualizer<any, any>,
312
+ instance: Virtualizer<TScrollElement, TItemElement>,
310
313
  ) => {
311
- instance.scrollElement?.scrollTo?.({
312
- [instance.options.horizontal ? 'left' : 'top']: offset + adjustments,
314
+ const { scrollElement, options } = instance
315
+ const adjustedOffset = offset + adjustments
316
+ const isRtlElement =
317
+ options.horizontal &&
318
+ options.isRtl &&
319
+ scrollElement !== null &&
320
+ 'ownerDocument' in scrollElement
321
+
322
+ scrollElement?.scrollTo?.({
323
+ [options.horizontal ? 'left' : 'top']: isRtlElement
324
+ ? -adjustedOffset
325
+ : adjustedOffset,
313
326
  behavior,
314
327
  })
315
328
  }
@@ -1860,16 +1873,23 @@ export class Virtualizer<
1860
1873
  this.getSize(),
1861
1874
  this.getScrollOffset(),
1862
1875
  this.options.lanes,
1876
+ // scrollOffset is measured in the scroll element and the layout total
1877
+ // from the list start, so the list ends scrollMargin further down.
1878
+ this._getLayoutTotalSize() + this.options.scrollMargin,
1863
1879
  ],
1864
- (measurements, outerSize, scrollOffset, lanes) => {
1880
+ (measurements, outerSize, scrollOffset, lanes, listEnd) => {
1865
1881
  if (measurements.length === 0 || outerSize === 0) {
1866
1882
  this.range = null
1867
1883
  return null
1868
1884
  }
1885
+ // Until the element reports a clamped position (the list shrank, a
1886
+ // rubber-band bounce), the offset can sit past the last row, which
1887
+ // would leave only that row in the range.
1888
+ const maxScrollOffset = Math.max(listEnd - outerSize, 0)
1869
1889
  this.range = calculateRangeImpl(
1870
1890
  measurements,
1871
1891
  outerSize,
1872
- scrollOffset,
1892
+ Math.min(scrollOffset, maxScrollOffset),
1873
1893
  lanes,
1874
1894
  // Pass the typed array so binary search + forward-walk can read
1875
1895
  // start/end directly from Float64Array, skipping the Proxy traps.
@@ -2369,7 +2389,9 @@ export class Virtualizer<
2369
2389
  const size = this.getSize()
2370
2390
  const scrollOffset = this.getScrollOffset()
2371
2391
 
2372
- const item = this.measurementsCache[index]
2392
+ // Not `measurementsCache`: that field is only rebuilt by getMeasurements,
2393
+ // so it lags a size change until the next render reads the items.
2394
+ const item = this.getMeasurements()[index]
2373
2395
  if (!item) return
2374
2396
 
2375
2397
  if (align === 'auto') {