fix(timeline): restore unconditional bottom-pin on load, cede observer mid-jump

The rebase resolution wrapped the ResizeObserver at-bottom re-pin in an isAtBottomNow(container) guard. On initial load the virtualizer grows scrollHeight a frame after the first pin (off-screen rows measure late) with no messages change, so the guard read ">2px from the new floor" and skipped the legitimate load-time floor pin, leaving the timeline not at bottom (scroll-history:190). Cede the whole callback while convergingTargetIdRef.current !== null \u2014 the precise jump-in-flight signal the geometry proxy was approximating, mirroring the layout effect's existing bail \u2014 and restore eva's unconditional at-bottom re-pin.

Co-authored-by: Will Pfleger <pfleger.will@gmail.com>
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
This commit is contained in:
npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7
2026-06-18 19:12:20 -04:00
parent 4127d37bf6
commit 4ac28bfd67

View File

@@ -541,19 +541,22 @@ export function useAnchoredScroll({
const observer = new ResizeObserver(() => {
const container = scrollContainerRef.current;
if (!container) return;
// Cede entirely while a convergence loop owns scroll (jump to a
// windowed-out target). Mid-jump the anchor is transiently `at-bottom`
// — `computeAnchor` finds no crossing row until the virtualizer renders
// rows at the new offset — so an unconditional re-pin here would yank
// the in-flight jump down to the floor as rows measure. The convergence
// loop is the sole writer until it settles (mirrors the layout effect's
// `convergingTargetIdRef` bail).
if (convergingTargetIdRef.current !== null) return;
const anchor = anchorRef.current;
if (anchor.kind === "at-bottom") {
// Pin to bottom only when the viewport is GENUINELY at the bottom
// right now — read live geometry, don't trust the cached anchor kind.
// After a programmatic jump into windowed-out history, the virtualizer
// needs a frame to render rows at the new offset; in that gap
// `computeAnchor` finds no crossing row and falls back to `at-bottom`,
// which would make this observer yank a mid-history restore down to
// the floor as the prepended rows measure. `isAtBottomNow` is the
// authoritative read; when it disagrees we leave the scroll alone.
if (isAtBottomNow(container)) {
container.scrollTo({ top: container.scrollHeight, behavior: "auto" });
}
// Stuck to bottom: re-pin to the new floor. Virtualizer measurement
// grows `scrollHeight` after the initial pin (rows below the fold
// measure a frame or two late) without any `messages` change to drive
// the layout effect, so this observer is the only thing that keeps the
// view glued to the bottom as content settles.
container.scrollTo({ top: container.scrollHeight, behavior: "auto" });
return;
}
// Use the same restore primitive as the layout effect so the