feat(app): make session timelines much faster AND without flicker or scroll jumps (#32331)

This commit is contained in:
Luke Parker 2026-06-16 18:53:57 +02:00 committed by GitHub
commit 3b811bd019
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
49 changed files with 2824 additions and 845 deletions

View file

@ -0,0 +1,45 @@
diff --git a/dist/cjs/index.cjs b/dist/cjs/index.cjs
index 7e97823ea769398ccd9cf449b178c77675ed252c..d75183f11421af0e20e4e8a996af99c300ad936d 100644
--- a/dist/cjs/index.cjs
+++ b/dist/cjs/index.cjs
@@ -39,7 +39,9 @@ function createVirtualizerBase(options) {
(_a = options.onChange) == null ? void 0 : _a.call(options, instance2, sync);
}
}));
- virtualizer.measure();
+ virtualizer._willUpdate();
+ setVirtualItems(store.reconcile(instance.getVirtualItems(), { key: "index" }));
+ setTotalSize(instance.getTotalSize());
});
return virtualizer;
}
diff --git a/dist/esm/index.js b/dist/esm/index.js
index 1d525463775fef3e8ece6ab191061ef9d0a36d73..14c680a2088c49a33959d8118cf32ee599ab83c2 100644
--- a/dist/esm/index.js
+++ b/dist/esm/index.js
@@ -38,7 +38,9 @@ function createVirtualizerBase(options) {
(_a = options.onChange) == null ? void 0 : _a.call(options, instance2, sync);
}
}));
- virtualizer.measure();
+ virtualizer._willUpdate();
+ setVirtualItems(reconcile(instance.getVirtualItems(), { key: "index" }));
+ setTotalSize(instance.getTotalSize());
});
return virtualizer;
}
diff --git a/src/index.tsx b/src/index.tsx
index 69ac34fd70753b9bd00683c2540be7f62630f8f2..9f16672aa0f4a044aa2b35754d385d7d8031f743 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -81,7 +81,9 @@ function createVirtualizerBase<
},
}),
)
- virtualizer.measure()
+ virtualizer._willUpdate()
+ setVirtualItems(reconcile(instance.getVirtualItems(), { key: 'index' }))
+ setTotalSize(instance.getTotalSize())
})
return virtualizer

View file

@ -0,0 +1,58 @@
diff --git a/dist/cjs/index.cjs b/dist/cjs/index.cjs
index df75d0cf0347b62906e04e454d4f4ef062ed5c48..58913f2d30e0beee9d09dffa5ebcaab4601a2c22 100644
--- a/dist/cjs/index.cjs
+++ b/dist/cjs/index.cjs
@@ -526,6 +526,7 @@ class Virtualizer {
this.scrollOffset = this.scrollOffset ?? (typeof this.options.initialOffset === "function" ? this.options.initialOffset() : this.options.initialOffset);
return this.scrollOffset;
};
+ this.getLogicalScrollOffset = () => this.getScrollOffset() + this.scrollAdjustments;
this.getFurthestMeasurement = (measurements, index) => {
const furthestMeasurementsFound = /* @__PURE__ */ new Map();
const furthestMeasurements = /* @__PURE__ */ new Map();
diff --git a/dist/cjs/index.d.cts b/dist/cjs/index.d.cts
index c61ee17752565253f795c7fc7d57e86237ecbb52..705bb7e3a121b040fb1a3e7890179eaa3e9b219e 100644
--- a/dist/cjs/index.d.cts
+++ b/dist/cjs/index.d.cts
@@ -108,6 +108,7 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
scrollRect: Rect | null;
scrollOffset: number | null;
scrollDirection: ScrollDirection | null;
+ getLogicalScrollOffset: () => number;
private scrollAdjustments;
private _iosDeferredAdjustment;
private _iosTouching;
diff --git a/dist/esm/index.d.ts b/dist/esm/index.d.ts
index b03abab604eb6578f6f56ff92c489259cfaf8f19..0495f372ea000dffc416c4f56809946f7ba73099 100644
--- a/dist/esm/index.d.ts
+++ b/dist/esm/index.d.ts
@@ -108,6 +108,7 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
scrollRect: Rect | null;
scrollOffset: number | null;
scrollDirection: ScrollDirection | null;
+ getLogicalScrollOffset: () => number;
private scrollAdjustments;
private _iosDeferredAdjustment;
private _iosTouching;
diff --git a/dist/esm/index.js b/dist/esm/index.js
index e384cf7541978a2782b9dca68146e869b16ac3f2..53b15b7a36247ea4aa5b70b00d08b6d7dec3ea79 100644
--- a/dist/esm/index.js
+++ b/dist/esm/index.js
@@ -524,6 +524,7 @@ class Virtualizer {
this.scrollOffset = this.scrollOffset ?? (typeof this.options.initialOffset === "function" ? this.options.initialOffset() : this.options.initialOffset);
return this.scrollOffset;
};
+ this.getLogicalScrollOffset = () => this.getScrollOffset() + this.scrollAdjustments;
this.getFurthestMeasurement = (measurements, index) => {
const furthestMeasurementsFound = /* @__PURE__ */ new Map();
const furthestMeasurements = /* @__PURE__ */ new Map();
diff --git a/src/index.ts b/src/index.ts
index d35b3e0695a9c85b261bc1a4fbe23c0a60d5b204..d516a9d00f1233173f9a3e2144666c8159552f91 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1050,3 +1050,5 @@ export class Virtualizer<
+ getLogicalScrollOffset = () => this.getScrollOffset() + this.scrollAdjustments
+
private getFurthestMeasurement = (
measurements: Array<VirtualItem>,
index: number,

View file

@ -1,93 +0,0 @@
diff --git a/lib/solid/Virtualizer.d.ts b/lib/solid/Virtualizer.d.ts
index 144dd7f..819aab9 100644
--- a/lib/solid/Virtualizer.d.ts
+++ b/lib/solid/Virtualizer.d.ts
@@ -38,6 +38,10 @@ export interface VirtualizerHandle {
* @param index index of item
*/
getItemSize(index: number): number;
+ /**
+ * Synchronously measure currently mounted items and update cached item sizes.
+ */
+ measure(): void;
/**
* Scroll to the item specified by index.
* @param index index of item
diff --git a/lib/solid/index.jsx b/lib/solid/index.jsx
index 029201a..3949cd4 100644
--- a/lib/solid/index.jsx
+++ b/lib/solid/index.jsx
@@ -1085,6 +1085,7 @@ const createResizer = (store, isHorizontal) => {
let viewportElement;
const sizeKey = isHorizontal ? "width" : "height";
const mountedIndexes = new WeakMap();
+ const mountedItems = new Map();
const resizeObserver = createResizeObserver((entries) => {
const resizes = [];
for (const { target, contentRect } of entries) {
@@ -1111,12 +1112,27 @@ const createResizer = (store, isHorizontal) => {
},
$observeItem: (el, i) => {
mountedIndexes.set(el, i);
+ mountedItems.set(i, el);
resizeObserver._observe(el);
return () => {
mountedIndexes.delete(el);
+ if (mountedItems.get(i) === el) {
+ mountedItems.delete(i);
+ }
resizeObserver._unobserve(el);
};
},
+ $measureItems: () => {
+ const resizes = [];
+ mountedItems.forEach((el, index) => {
+ if (!el.offsetParent)
+ return;
+ resizes.push([index, el.getBoundingClientRect()[sizeKey]]);
+ });
+ if (resizes.length) {
+ store.$update(ACTION_ITEM_RESIZE, resizes);
+ }
+ },
$dispose: resizeObserver._dispose,
};
};
@@ -1354,6 +1370,8 @@ const Virtualizer = (props) => {
const range = createMemo((prev) => {
stateVersion();
const next = store.$getRange(props.bufferSize);
+ next[0] = Math.max(0, next[0]);
+ next[1] = Math.min(props.data.length - 1, next[1]);
if (prev && isSameRange(prev, next)) {
return prev;
}
@@ -1380,6 +1398,7 @@ const Virtualizer = (props) => {
findItemIndex: store.$findItemIndex,
getItemOffset: store.$getItemOffset,
getItemSize: store.$getItemSize,
+ measure: resizer.$measureItems,
scrollToIndex: scroller.$scrollToIndex,
scrollTo: scroller.$scrollTo,
scrollBy: scroller.$scrollBy,
@@ -1417,6 +1436,11 @@ const Virtualizer = (props) => {
const indexes = [];
if (props.keepMounted) {
const mounted = new Set(props.keepMounted);
+ mounted.forEach((index) => {
+ if (index < 0 || index >= count) {
+ mounted.delete(index);
+ }
+ });
for (let [i, j] = range(); i <= j; i++) {
mounted.add(i);
}
@@ -1528,6 +1552,8 @@ const WindowVirtualizer = (props) => {
const range = createMemo((prev) => {
stateVersion();
const next = store.$getRange(props.bufferSize);
+ next[0] = Math.max(0, next[0]);
+ next[1] = Math.min(props.data.length - 1, next[1]);
if (prev && isSameRange(prev, next)) {
return prev;
}