@tanstack/virtual-core 3.19.8 → 3.19.10

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.
@@ -255,6 +255,9 @@ class Virtualizer {
255
255
  this.observer = /* @__PURE__ */ (() => {
256
256
  let _ro = null;
257
257
  let _frames = null;
258
+ let delivering = false;
259
+ let observeQueued = false;
260
+ const pendingObservations = /* @__PURE__ */ new Set();
258
261
  const get = () => {
259
262
  if (_ro) {
260
263
  return _ro;
@@ -277,10 +280,20 @@ class Virtualizer {
277
280
  this._noteClampMax();
278
281
  this._flushHoldIfReady(true);
279
282
  this._retryClampedAdjustment();
283
+ this.measureElement(null);
280
284
  }
281
285
  }
282
286
  };
283
- this.options.useAnimationFrameWithResizeObserver ? frames.schedule(run) : run();
287
+ if (this.options.useAnimationFrameWithResizeObserver) {
288
+ frames.schedule(run);
289
+ } else {
290
+ delivering = true;
291
+ try {
292
+ run();
293
+ } finally {
294
+ delivering = false;
295
+ }
296
+ }
284
297
  });
285
298
  };
286
299
  const measureEntry = (entry) => {
@@ -306,16 +319,34 @@ class Virtualizer {
306
319
  var _a;
307
320
  (_a = get()) == null ? void 0 : _a.disconnect();
308
321
  _frames == null ? void 0 : _frames.cancel();
322
+ pendingObservations.clear();
323
+ observeQueued = false;
309
324
  _ro = null;
310
325
  _frames = null;
311
326
  },
312
327
  observe: (target) => {
313
- var _a;
314
- return (_a = get()) == null ? void 0 : _a.observe(target, { box: "border-box" });
328
+ const observer = get();
329
+ if (!observer) return;
330
+ if (!delivering) {
331
+ observer.observe(target, { box: "border-box" });
332
+ return;
333
+ }
334
+ pendingObservations.add(target);
335
+ if (!observeQueued) {
336
+ observeQueued = true;
337
+ _frames == null ? void 0 : _frames.schedule(() => {
338
+ observeQueued = false;
339
+ pendingObservations.forEach((node) => {
340
+ if (node.isConnected) _ro == null ? void 0 : _ro.observe(node, { box: "border-box" });
341
+ });
342
+ pendingObservations.clear();
343
+ });
344
+ }
315
345
  },
316
346
  unobserve: (target) => {
317
347
  var _a;
318
- return (_a = get()) == null ? void 0 : _a.unobserve(target);
348
+ pendingObservations.delete(target);
349
+ (_a = get()) == null ? void 0 : _a.unobserve(target);
319
350
  }
320
351
  };
321
352
  })();
@@ -878,17 +909,21 @@ class Virtualizer {
878
909
  this.getMeasurements(),
879
910
  this.getSize(),
880
911
  this.getScrollOffset(),
881
- this.options.lanes
912
+ this.options.lanes,
913
+ // scrollOffset is measured in the scroll element and the layout total
914
+ // from the list start, so the list ends scrollMargin further down.
915
+ this._getLayoutTotalSize() + this.options.scrollMargin
882
916
  ],
883
- (measurements, outerSize, scrollOffset, lanes) => {
917
+ (measurements, outerSize, scrollOffset, lanes, listEnd) => {
884
918
  if (measurements.length === 0 || outerSize === 0) {
885
919
  this.range = null;
886
920
  return null;
887
921
  }
922
+ const maxScrollOffset = Math.max(listEnd - outerSize, 0);
888
923
  this.range = calculateRangeImpl(
889
924
  measurements,
890
925
  outerSize,
891
- scrollOffset,
926
+ Math.min(scrollOffset, maxScrollOffset),
892
927
  lanes,
893
928
  // Pass the typed array so binary search + forward-walk can read
894
929
  // start/end directly from Float64Array, skipping the Proxy traps.
@@ -1155,7 +1190,13 @@ class Virtualizer {
1155
1190
  const property = this.options.horizontal ? "overflow-x" : "overflow-y";
1156
1191
  const value = style.getPropertyValue(property);
1157
1192
  const priority = style.getPropertyPriority(property);
1193
+ const crossSize = () => this.options.horizontal ? scroller.clientHeight : scroller.clientWidth;
1194
+ const crossSizeBefore = crossSize();
1158
1195
  style.setProperty(property, "hidden", "important");
1196
+ if (crossSize() !== crossSizeBefore) {
1197
+ style.setProperty(property, value, priority);
1198
+ return;
1199
+ }
1159
1200
  const stop = {
1160
1201
  // False when the app replaced the hidden value: the fling may not
1161
1202
  // have stopped.
@@ -1491,7 +1532,7 @@ class Virtualizer {
1491
1532
  this._clampedAdjustment = null;
1492
1533
  const tail = this._iosGesture.tail();
1493
1534
  if (kind === "absolute" && tail !== null) {
1494
- if (tail === "fling" && iosGesture.iosMomentumOverridesWrites()) {
1535
+ if (tail === "fling" && iosGesture.momentumOverridesWrites()) {
1495
1536
  this._stopMomentum(() => {
1496
1537
  const state = this.scrollState;
1497
1538
  if ((state == null ? void 0 : state.phase) !== "queued" || // A finger came down: it owns the scroll until it lifts.