@tanstack/virtual-core 3.19.7 → 3.19.9

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
  })();
@@ -1155,7 +1186,13 @@ class Virtualizer {
1155
1186
  const property = this.options.horizontal ? "overflow-x" : "overflow-y";
1156
1187
  const value = style.getPropertyValue(property);
1157
1188
  const priority = style.getPropertyPriority(property);
1189
+ const crossSize = () => this.options.horizontal ? scroller.clientHeight : scroller.clientWidth;
1190
+ const crossSizeBefore = crossSize();
1158
1191
  style.setProperty(property, "hidden", "important");
1192
+ if (crossSize() !== crossSizeBefore) {
1193
+ style.setProperty(property, value, priority);
1194
+ return;
1195
+ }
1159
1196
  const stop = {
1160
1197
  // False when the app replaced the hidden value: the fling may not
1161
1198
  // have stopped.
@@ -1185,7 +1222,7 @@ class Virtualizer {
1185
1222
  };
1186
1223
  this.getVirtualDistanceFromEnd = () => {
1187
1224
  return Math.max(
1188
- this._getLayoutTotalSize() - this.getSize() - this.getScrollOffset(),
1225
+ this._getLayoutTotalSize() + this.options.scrollMargin - this.getSize() - this.getScrollOffset(),
1189
1226
  0
1190
1227
  );
1191
1228
  };
@@ -1491,7 +1528,7 @@ class Virtualizer {
1491
1528
  this._clampedAdjustment = null;
1492
1529
  const tail = this._iosGesture.tail();
1493
1530
  if (kind === "absolute" && tail !== null) {
1494
- if (tail === "fling" && iosGesture.iosMomentumOverridesWrites()) {
1531
+ if (tail === "fling" && iosGesture.momentumOverridesWrites()) {
1495
1532
  this._stopMomentum(() => {
1496
1533
  const state = this.scrollState;
1497
1534
  if ((state == null ? void 0 : state.phase) !== "queued" || // A finger came down: it owns the scroll until it lifts.