Virtual log: a page that lands keeps the row nearest the view's middle still
Jonas Templestein, 2026-11-28 16:55 UTC · 90a49804ef0453ec39086b101784da27ab720257 · parent 59d04eb
1 file changed
M src/components/virtual-log/virtual-log.tsx
@@ -668,14 +668,25 @@ const candidates = offsetCandidates.size > 0 ? offsetCandidates : anyCandidates; if (candidates.size === 0) return null; instance.getTotalSize(); + // THE ROW THAT THE READER LOOKS AT STANDS STILL: of the rows that are still there, the one that + // began nearest the view's middle. A page that lands can also change rows in the view (a fold + // that takes older events in, a row that hides): held by the first row of the view, everything + // under such a row moved (the Dash's feed, 28 Nov 2026: 1,263 px, 0.4 s after the reader left + // the list's end). + const middle = liveTop + (instance.scrollRect?.height ?? 0) / 2; + let delta: number | null = null; + let nearest = Infinity; for (let i = 0; i < rows.length; i += 1) { const oldStart = candidates.get(rowInfo.key(rows[i]!)); if (oldStart === undefined) continue; const nextItem = instance.measurementsCache[i]; if (!nextItem) continue; - return nextItem.start - oldStart; + const distance = Math.abs(oldStart - middle); + if (distance >= nearest) continue; + nearest = distance; + delta = nextItem.start - oldStart; } - return null; + return delta; } /** Matches `@tanstack/virtual-core`'s iOS WebKit check so we never write `scrollTop` during an