@tanstack/virtual-core 3.19.14 → 3.19.15

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.14",
3
+ "version": "3.19.15",
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
@@ -679,6 +679,8 @@ export class Virtualizer<
679
679
  // Set while a ResizeObserver callback measures its entries; `resizeItem`
680
680
  // records the pending notify here instead of firing it per entry.
681
681
  private _resizeBatch: { sync: boolean; notify?: boolean } | null = null
682
+ // Set while a microtask waits to run `dropDisconnected` again.
683
+ private _dropQueued = false
682
684
  private now = () => this.targetWindow?.performance?.now?.() ?? Date.now()
683
685
  private observer = (() => {
684
686
  let _ro: ResizeObserver | null = null
@@ -2135,14 +2137,31 @@ export class Virtualizer<
2135
2137
  return true
2136
2138
  }
2137
2139
 
2140
+ private dropDisconnected = () => {
2141
+ this.elementsCache.forEach((cached, key) => {
2142
+ if (!cached.isConnected) {
2143
+ this.observer.unobserve(cached)
2144
+ this.elementsCache.delete(key)
2145
+ }
2146
+ })
2147
+ }
2148
+
2138
2149
  measureElement = (node: TItemElement | null) => {
2139
2150
  if (!node) {
2140
- this.elementsCache.forEach((cached, key) => {
2141
- if (!cached.isConnected) {
2142
- this.observer.unobserve(cached)
2143
- this.elementsCache.delete(key)
2144
- }
2145
- })
2151
+ this.dropDisconnected()
2152
+ // A framework clears the ref before it detaches the element, so the row
2153
+ // that is unmounting is still connected here. A render in a microtask of
2154
+ // a ResizeObserver delivery (Vue does this) detaches it before the
2155
+ // browser gathers the next observations, and a detached row that is
2156
+ // still observed at that point makes the browser report a loop error.
2157
+ // Check again once the render is done.
2158
+ if (!this._dropQueued) {
2159
+ this._dropQueued = true
2160
+ queueMicrotask(() => {
2161
+ this._dropQueued = false
2162
+ this.dropDisconnected()
2163
+ })
2164
+ }
2146
2165
  return
2147
2166
  }
2148
2167
 
@@ -2692,7 +2711,8 @@ export class Virtualizer<
2692
2711
  // before the command (below). One held for a touch or a bounce is not
2693
2712
  // dropped by a command: the write lands the element `_holdOffset` short
2694
2713
  // of the target, under the rows exposed shifted by the same amount, and
2695
- // the flush moves both together once a write is possible.
2714
+ // the flush moves both together once a write is possible. Unless the
2715
+ // target is less than the hold (below).
2696
2716
  //
2697
2717
  // An index or end target that is already at its offset starts a smooth
2698
2718
  // scroll as landed; an offset target never does, so its first scroll
@@ -2773,6 +2793,21 @@ export class Virtualizer<
2773
2793
  // scroll: leave it.
2774
2794
  this._iosGesture.end()
2775
2795
  }
2796
+ // A target less than the hold is out of the element's reach: written
2797
+ // the hold short, the write clamps at the element's 0, and the read-back
2798
+ // looks like a scroll away from the target (#1405). Write the hold first
2799
+ // where a write is possible now (the command has closed a tap's tail),
2800
+ // as for the wheel above. Its clamp retry would write over the command.
2801
+ // The target was clamped to a max that included the hold; a consumer
2802
+ // that commits the sizer after the notify leaves the element its old
2803
+ // max, so clamp it again, as for a command issued now. Reconcile
2804
+ // retargets an index or end target once the sizer grows.
2805
+ if (offset < this._holdOffset && this._canWriteScroll()) {
2806
+ this.scrollState = null
2807
+ this._flushHoldIfReady(true)
2808
+ this._clampedAdjustment = null
2809
+ offset = Math.min(offset, Math.max(this.getMaxScrollOffset(), 0))
2810
+ }
2776
2811
  this.scrollState = {
2777
2812
  ...target,
2778
2813
  startedAt: this.now(),