@tanstack/virtual-core 3.17.3 → 3.17.4
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 +37 -37
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +0 -1
- package/dist/esm/index.d.ts +0 -1
- package/dist/esm/index.js +37 -37
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +57 -58
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -741,6 +741,19 @@ export class Virtualizer<
|
|
|
741
741
|
this.rafId = null
|
|
742
742
|
}
|
|
743
743
|
this.scrollState = null
|
|
744
|
+
// The iOS gesture/deferral state is scoped to the current scroll
|
|
745
|
+
// element: the touch listeners that maintain it were just removed, and
|
|
746
|
+
// an in-flight touch keeps targeting the old element (implicit touch
|
|
747
|
+
// capture), so the new element never reports it. Carrying the state
|
|
748
|
+
// over would replay a stale deferred delta on the new element's first
|
|
749
|
+
// flush, and a cleanup that lands mid-touch or inside the post-touchend
|
|
750
|
+
// grace window would strand _iosTouching / _iosJustTouchEnded as true
|
|
751
|
+
// (the listener unsub clears the grace timer, and with it the only
|
|
752
|
+
// pending reset of the flag), deferring every adjustment on the new
|
|
753
|
+
// element until its next touch cycle.
|
|
754
|
+
this._iosDeferredAdjustment = 0
|
|
755
|
+
this._iosTouching = false
|
|
756
|
+
this._iosJustTouchEnded = false
|
|
744
757
|
this.scrollElement = null
|
|
745
758
|
this.targetWindow = null
|
|
746
759
|
}
|
|
@@ -1082,47 +1095,6 @@ export class Virtualizer<
|
|
|
1082
1095
|
return this.scrollOffset
|
|
1083
1096
|
}
|
|
1084
1097
|
|
|
1085
|
-
private getFurthestMeasurement = (
|
|
1086
|
-
measurements: Array<VirtualItem>,
|
|
1087
|
-
index: number,
|
|
1088
|
-
) => {
|
|
1089
|
-
const furthestMeasurementsFound = new Map<number, true>()
|
|
1090
|
-
const furthestMeasurements = new Map<number, VirtualItem>()
|
|
1091
|
-
for (let m = index - 1; m >= 0; m--) {
|
|
1092
|
-
const measurement = measurements[m]!
|
|
1093
|
-
|
|
1094
|
-
if (furthestMeasurementsFound.has(measurement.lane)) {
|
|
1095
|
-
continue
|
|
1096
|
-
}
|
|
1097
|
-
|
|
1098
|
-
const previousFurthestMeasurement = furthestMeasurements.get(
|
|
1099
|
-
measurement.lane,
|
|
1100
|
-
)
|
|
1101
|
-
if (
|
|
1102
|
-
previousFurthestMeasurement == null ||
|
|
1103
|
-
measurement.end > previousFurthestMeasurement.end
|
|
1104
|
-
) {
|
|
1105
|
-
furthestMeasurements.set(measurement.lane, measurement)
|
|
1106
|
-
} else if (measurement.end < previousFurthestMeasurement.end) {
|
|
1107
|
-
furthestMeasurementsFound.set(measurement.lane, true)
|
|
1108
|
-
}
|
|
1109
|
-
|
|
1110
|
-
if (furthestMeasurementsFound.size === this.options.lanes) {
|
|
1111
|
-
break
|
|
1112
|
-
}
|
|
1113
|
-
}
|
|
1114
|
-
|
|
1115
|
-
return furthestMeasurements.size === this.options.lanes
|
|
1116
|
-
? Array.from(furthestMeasurements.values()).sort((a, b) => {
|
|
1117
|
-
if (a.end === b.end) {
|
|
1118
|
-
return a.index - b.index
|
|
1119
|
-
}
|
|
1120
|
-
|
|
1121
|
-
return a.end - b.end
|
|
1122
|
-
})[0]
|
|
1123
|
-
: undefined
|
|
1124
|
-
}
|
|
1125
|
-
|
|
1126
1098
|
private getMeasurementOptions = memo(
|
|
1127
1099
|
() => [
|
|
1128
1100
|
this.options.count,
|
|
@@ -1132,6 +1104,7 @@ export class Virtualizer<
|
|
|
1132
1104
|
this.options.enabled,
|
|
1133
1105
|
this.options.lanes,
|
|
1134
1106
|
this.options.laneAssignmentMode,
|
|
1107
|
+
this.options.gap,
|
|
1135
1108
|
],
|
|
1136
1109
|
(
|
|
1137
1110
|
count,
|
|
@@ -1141,6 +1114,7 @@ export class Virtualizer<
|
|
|
1141
1114
|
enabled,
|
|
1142
1115
|
lanes,
|
|
1143
1116
|
laneAssignmentMode,
|
|
1117
|
+
gap,
|
|
1144
1118
|
) => {
|
|
1145
1119
|
const lanesChanged =
|
|
1146
1120
|
this.prevLanes !== undefined && this.prevLanes !== lanes
|
|
@@ -1161,6 +1135,7 @@ export class Virtualizer<
|
|
|
1161
1135
|
enabled,
|
|
1162
1136
|
lanes,
|
|
1163
1137
|
laneAssignmentMode,
|
|
1138
|
+
gap,
|
|
1164
1139
|
}
|
|
1165
1140
|
},
|
|
1166
1141
|
{
|
|
@@ -1179,6 +1154,7 @@ export class Virtualizer<
|
|
|
1179
1154
|
enabled,
|
|
1180
1155
|
lanes,
|
|
1181
1156
|
laneAssignmentMode,
|
|
1157
|
+
gap,
|
|
1182
1158
|
},
|
|
1183
1159
|
_itemSizeCacheVersion,
|
|
1184
1160
|
) => {
|
|
@@ -1237,7 +1213,6 @@ export class Virtualizer<
|
|
|
1237
1213
|
// At n=100k this drops cold-mount cost from ~2.5ms (eager object
|
|
1238
1214
|
// allocation) to roughly the cost of a single typed-array fill.
|
|
1239
1215
|
if (lanes === 1) {
|
|
1240
|
-
const gap = this.options.gap
|
|
1241
1216
|
// Reuse flat backing if large enough; else grow (preserving data
|
|
1242
1217
|
// before `min` to mirror the slice-and-rebuild contract).
|
|
1243
1218
|
const need = count * 2
|
|
@@ -1281,12 +1256,21 @@ export class Virtualizer<
|
|
|
1281
1256
|
const laneLastIndex: Array<number | undefined> = new Array(lanes).fill(
|
|
1282
1257
|
undefined,
|
|
1283
1258
|
)
|
|
1259
|
+
// Running end position of each lane's last item, so the shortest lane
|
|
1260
|
+
// can be found with an O(lanes) argmin instead of the old backward walk
|
|
1261
|
+
// through `measurements` (getFurthestMeasurement). `filledLanes` tracks
|
|
1262
|
+
// how many lanes have at least one item, mirroring the previous
|
|
1263
|
+
// "all lanes seen → shortest lane, else i % lanes" branch.
|
|
1264
|
+
const laneEnds = new Float64Array(lanes)
|
|
1265
|
+
let filledLanes = 0
|
|
1284
1266
|
|
|
1285
1267
|
// Initialize from existing measurements (before min)
|
|
1286
1268
|
for (let m = 0; m < min; m++) {
|
|
1287
1269
|
const item = measurements[m]
|
|
1288
1270
|
if (item) {
|
|
1271
|
+
if (laneLastIndex[item.lane] === undefined) filledLanes++
|
|
1289
1272
|
laneLastIndex[item.lane] = m
|
|
1273
|
+
laneEnds[item.lane] = item.end
|
|
1290
1274
|
}
|
|
1291
1275
|
}
|
|
1292
1276
|
|
|
@@ -1308,24 +1292,37 @@ export class Virtualizer<
|
|
|
1308
1292
|
const prevInLane =
|
|
1309
1293
|
prevIndex !== undefined ? measurements[prevIndex] : undefined
|
|
1310
1294
|
start = prevInLane
|
|
1311
|
-
? prevInLane.end +
|
|
1312
|
-
: paddingStart + scrollMargin
|
|
1313
|
-
} else {
|
|
1314
|
-
// No cache - use original logic (find shortest lane)
|
|
1315
|
-
const furthestMeasurement =
|
|
1316
|
-
this.options.lanes === 1
|
|
1317
|
-
? measurements[i - 1]
|
|
1318
|
-
: this.getFurthestMeasurement(measurements, i)
|
|
1319
|
-
|
|
1320
|
-
start = furthestMeasurement
|
|
1321
|
-
? furthestMeasurement.end + this.options.gap
|
|
1295
|
+
? prevInLane.end + gap
|
|
1322
1296
|
: paddingStart + scrollMargin
|
|
1297
|
+
} else if (filledLanes === lanes) {
|
|
1298
|
+
// No cache, every lane seeded: place in the shortest lane.
|
|
1299
|
+
// Read the running per-lane ends (O(lanes) argmin) instead of the
|
|
1300
|
+
// old backward scan. Tie-break on the lane's last-item index to
|
|
1301
|
+
// preserve the previous sort-by-(end, index) placement exactly.
|
|
1302
|
+
let bestLane = 0
|
|
1303
|
+
let bestEnd = laneEnds[0]!
|
|
1304
|
+
let bestIdx = laneLastIndex[0]!
|
|
1305
|
+
for (let l = 1; l < lanes; l++) {
|
|
1306
|
+
const e = laneEnds[l]!
|
|
1307
|
+
if (e < bestEnd || (e === bestEnd && laneLastIndex[l]! < bestIdx)) {
|
|
1308
|
+
bestLane = l
|
|
1309
|
+
bestEnd = e
|
|
1310
|
+
bestIdx = laneLastIndex[l]!
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
lane = bestLane
|
|
1314
|
+
start = bestEnd + gap
|
|
1323
1315
|
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1316
|
+
if (shouldCacheLane) {
|
|
1317
|
+
this.laneAssignments.set(i, lane)
|
|
1318
|
+
}
|
|
1319
|
+
} else {
|
|
1320
|
+
// No cache and not every lane seeded yet — seed lanes in order,
|
|
1321
|
+
// matching the previous `i % lanes` fallback for the first row.
|
|
1322
|
+
lane = i % this.options.lanes
|
|
1323
|
+
start = paddingStart + scrollMargin
|
|
1327
1324
|
|
|
1328
|
-
if (
|
|
1325
|
+
if (shouldCacheLane) {
|
|
1329
1326
|
this.laneAssignments.set(i, lane)
|
|
1330
1327
|
}
|
|
1331
1328
|
}
|
|
@@ -1347,8 +1344,10 @@ export class Virtualizer<
|
|
|
1347
1344
|
lane,
|
|
1348
1345
|
}
|
|
1349
1346
|
|
|
1350
|
-
// ✅ Performance: Update lane's last item index
|
|
1347
|
+
// ✅ Performance: Update lane's last item index + running end
|
|
1348
|
+
if (laneLastIndex[lane] === undefined) filledLanes++
|
|
1351
1349
|
laneLastIndex[lane] = i
|
|
1350
|
+
laneEnds[lane] = end
|
|
1352
1351
|
}
|
|
1353
1352
|
|
|
1354
1353
|
this.measurementsCache = measurements
|