iterate.com / ui

git clone https://git.iterate.com/repos/ui

Virtual log: a page that lands keeps the row nearest the view's middle still (#17)

When an older page lands, the list keeps the surviving row nearest the view's middle still (it was the first surviving row of the view).

Why: on the Dash's feed a landing page also changes rows in the view (folds, hidden rows); once the rows under them moved by 1,263 px (28 Nov 2026 16:52 UTC, measured with /repos/chat perf/scroll-check.mjs). Card: tasks/make-the-dash-scroll-and-render-smoothly-on-large-logs-like.md.

Checks: pnpm check passes (1,268 tests); scripts/check-virtual-log-scroll.ts: 0 jumps in 10 scenarios.

Session: claude e7bfeefe-1067-494b-8f63-82177cb1beb9 on beelink

🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_0158EjAGDfCugWqZ9a2JTTgL

Iterate-Run: /@1827943

jonas, 2026-11-28 16:55 UTC · bc5f047f628d50006312305eb0070c2e47f8f25c · 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