@tanstack/virtual-core 3.19.14 → 3.19.16
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/dist/cjs/index.cjs +28 -7
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +2 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +28 -7
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +49 -7
package/package.json
CHANGED
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
|
|
@@ -1153,12 +1155,19 @@ export class Virtualizer<
|
|
|
1153
1155
|
this.observer.observe(cached)
|
|
1154
1156
|
})
|
|
1155
1157
|
|
|
1158
|
+
let observing = false
|
|
1156
1159
|
this.unsubs.push(
|
|
1157
1160
|
this.options.observeElementRect(this, (rect) => {
|
|
1158
1161
|
this.scrollRect = rect
|
|
1159
1162
|
this.maybeNotify()
|
|
1163
|
+
// A render inside a delivery can detach rows without a ref-null
|
|
1164
|
+
// callback (Solid never makes one). Drop them as the row observer
|
|
1165
|
+
// does. The first call is the initial read, not a delivery, and
|
|
1166
|
+
// rows that are not attached yet stay observed through it.
|
|
1167
|
+
if (observing) this.measureElement(null)
|
|
1160
1168
|
}),
|
|
1161
1169
|
)
|
|
1170
|
+
observing = true
|
|
1162
1171
|
|
|
1163
1172
|
this.unsubs.push(
|
|
1164
1173
|
this.options.observeElementOffset(this, (offset, isScrolling) => {
|
|
@@ -2135,14 +2144,31 @@ export class Virtualizer<
|
|
|
2135
2144
|
return true
|
|
2136
2145
|
}
|
|
2137
2146
|
|
|
2147
|
+
private dropDisconnected = () => {
|
|
2148
|
+
this.elementsCache.forEach((cached, key) => {
|
|
2149
|
+
if (!cached.isConnected) {
|
|
2150
|
+
this.observer.unobserve(cached)
|
|
2151
|
+
this.elementsCache.delete(key)
|
|
2152
|
+
}
|
|
2153
|
+
})
|
|
2154
|
+
}
|
|
2155
|
+
|
|
2138
2156
|
measureElement = (node: TItemElement | null) => {
|
|
2139
2157
|
if (!node) {
|
|
2140
|
-
this.
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2158
|
+
this.dropDisconnected()
|
|
2159
|
+
// A framework clears the ref before it detaches the element, so the row
|
|
2160
|
+
// that is unmounting is still connected here. A render in a microtask of
|
|
2161
|
+
// a ResizeObserver delivery (Vue does this) detaches it before the
|
|
2162
|
+
// browser gathers the next observations, and a detached row that is
|
|
2163
|
+
// still observed at that point makes the browser report a loop error.
|
|
2164
|
+
// Check again once the render is done.
|
|
2165
|
+
if (!this._dropQueued) {
|
|
2166
|
+
this._dropQueued = true
|
|
2167
|
+
queueMicrotask(() => {
|
|
2168
|
+
this._dropQueued = false
|
|
2169
|
+
this.dropDisconnected()
|
|
2170
|
+
})
|
|
2171
|
+
}
|
|
2146
2172
|
return
|
|
2147
2173
|
}
|
|
2148
2174
|
|
|
@@ -2692,7 +2718,8 @@ export class Virtualizer<
|
|
|
2692
2718
|
// before the command (below). One held for a touch or a bounce is not
|
|
2693
2719
|
// dropped by a command: the write lands the element `_holdOffset` short
|
|
2694
2720
|
// of the target, under the rows exposed shifted by the same amount, and
|
|
2695
|
-
// the flush moves both together once a write is possible.
|
|
2721
|
+
// the flush moves both together once a write is possible. Unless the
|
|
2722
|
+
// target is less than the hold (below).
|
|
2696
2723
|
//
|
|
2697
2724
|
// An index or end target that is already at its offset starts a smooth
|
|
2698
2725
|
// scroll as landed; an offset target never does, so its first scroll
|
|
@@ -2773,6 +2800,21 @@ export class Virtualizer<
|
|
|
2773
2800
|
// scroll: leave it.
|
|
2774
2801
|
this._iosGesture.end()
|
|
2775
2802
|
}
|
|
2803
|
+
// A target less than the hold is out of the element's reach: written
|
|
2804
|
+
// the hold short, the write clamps at the element's 0, and the read-back
|
|
2805
|
+
// looks like a scroll away from the target (#1405). Write the hold first
|
|
2806
|
+
// where a write is possible now (the command has closed a tap's tail),
|
|
2807
|
+
// as for the wheel above. Its clamp retry would write over the command.
|
|
2808
|
+
// The target was clamped to a max that included the hold; a consumer
|
|
2809
|
+
// that commits the sizer after the notify leaves the element its old
|
|
2810
|
+
// max, so clamp it again, as for a command issued now. Reconcile
|
|
2811
|
+
// retargets an index or end target once the sizer grows.
|
|
2812
|
+
if (offset < this._holdOffset && this._canWriteScroll()) {
|
|
2813
|
+
this.scrollState = null
|
|
2814
|
+
this._flushHoldIfReady(true)
|
|
2815
|
+
this._clampedAdjustment = null
|
|
2816
|
+
offset = Math.min(offset, Math.max(this.getMaxScrollOffset(), 0))
|
|
2817
|
+
}
|
|
2776
2818
|
this.scrollState = {
|
|
2777
2819
|
...target,
|
|
2778
2820
|
startedAt: this.now(),
|