From 8d0c534b6f35170c9b234062587c0c65f0ef38d6 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 8 Nov 2026 18:10:33 +0000 Subject: [PATCH 1/7] test(web): reproduce #33027, minimap next turn enabled at the bottom At the bottom of a thread whose last few turns fit on one screen, the minimap's current turn is the first one in view, so "Next turn" stays enabled although the timeline cannot scroll any further. This test reproduces pingdotgg/t3code#33027 and fails on main. AI-assisted; verified with the tests and tools listed above. --- .../chat/MessagesTimeline.browser.test.tsx | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx b/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx index 46ce247ba6af8..94b6e0f47f9c4 100644 --- a/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx +++ b/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx @@ -434,6 +434,34 @@ describe("MessagesTimeline messages", () => { await expectHeadingInView("Last turn", "Turn 118:"); }); + it("disables the minimap's next turn button at the bottom of the thread", async () => { + setup(); + const props = baseProps(); + const entries = Array.from({ length: 16 }, (_, index) => [ + message(`Question ${index}`, {}, `user-${index}`), + message(`Answer ${index}`, { role: "assistant" }, `assistant-${index}`), + ]).flat(); + await using screen = await renderTimeline(entries, props); + const viewport = props.listRef.current!.getScrollableNode()!; + const strips = () => [ + ...screen.container.querySelectorAll("[data-minimap-strip]"), + ]; + // Several final turns share the last screen, so the current turn is not the last one. + await vi.waitFor(() => { + expect(viewport.scrollTop).toBeGreaterThan(0); + expect(viewport.scrollHeight - viewport.clientHeight - viewport.scrollTop).toBeLessThan(2); + expect(strips()[0]?.dataset.inView).toBe("false"); + expect( + strips() + .slice(-2) + .map((strip) => strip.dataset.inView), + ).toEqual(["true", "true"]); + expect(screen.button("Previous turn")).not.toBeDisabled(); + }); + + expect(screen.button("Next turn")).toBeDisabled(); + }); + it("keeps rows in item order after a reload or thread switch, before any timer runs", async () => { setup(); // NVDA's browse mode keeps the first DOM order it reads, so a timer that sorts rows later is too late. From 169269863a03265fa4bcb46ef40f670ee36dcc85 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 8 Nov 2026 18:14:10 +0000 Subject: [PATCH 2/7] fix(web): minimap next turn is disabled at the bottom of a thread The minimap's current turn is the first user message in view, so at the bottom of a thread whose last turns share one screen, "Next turn" stayed enabled and clicking it did nothing. refreshMinimap now also tracks whether the timeline is at its end, using resolveTimelineIsAtEnd, and the minimap has no next item there. Fixes pingdotgg/t3code#33027. AI-assisted; verified with the tests and tools listed above. --- apps/web/src/components/chat/MessagesTimeline.tsx | 3 +++ apps/web/src/components/chat/TimelineMinimap.tsx | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/web/src/components/chat/MessagesTimeline.tsx b/apps/web/src/components/chat/MessagesTimeline.tsx index 28d3299a7bd6d..96e06c6912773 100644 --- a/apps/web/src/components/chat/MessagesTimeline.tsx +++ b/apps/web/src/components/chat/MessagesTimeline.tsx @@ -818,6 +818,7 @@ const ConversationTimeline = memo(function ConversationTimeline({ }; const [minimapHitStripWidth, setMinimapHitStripWidth] = useState(0); const [minimapCurrentIndex, setMinimapCurrentIndex] = useState(null); + const [minimapAtEnd, setMinimapAtEnd] = useState(false); const handleAnchorReady = (info: { anchorIndex: number | undefined }) => { if (anchorMessageId !== null && info.anchorIndex !== undefined) { onAnchorReady(anchorMessageId, info.anchorIndex); @@ -889,6 +890,7 @@ const ConversationTimeline = memo(function ConversationTimeline({ setMinimapCurrentIndex((current) => current === nextCurrentIndex ? current : nextCurrentIndex, ); + setMinimapAtEnd(resolveTimelineIsAtEnd(state) ?? false); }); const minimapRefreshFrameRef = useRef(null); @@ -1370,6 +1372,7 @@ const ConversationTimeline = memo(function ConversationTimeline({ hasPersistentGutter={minimapHasPersistentGutter} hitStripWidth={minimapHitStripWidth} currentIndex={minimapCurrentIndex} + atEnd={minimapAtEnd} stripMap={minimapStripMap} onWheel={forwardMinimapWheel} onSelect={(item) => { diff --git a/apps/web/src/components/chat/TimelineMinimap.tsx b/apps/web/src/components/chat/TimelineMinimap.tsx index 44747a808a219..3aefd3c34e6ab 100644 --- a/apps/web/src/components/chat/TimelineMinimap.tsx +++ b/apps/web/src/components/chat/TimelineMinimap.tsx @@ -38,6 +38,7 @@ export function TimelineMinimap({ hasPersistentGutter, hitStripWidth, currentIndex, + atEnd, items, stripMap, onWheel, @@ -46,6 +47,7 @@ export function TimelineMinimap({ hasPersistentGutter: boolean; hitStripWidth: number; currentIndex: number | null; + atEnd: boolean; items: ReadonlyArray; stripMap: Map; onWheel: (event: WheelEvent) => void; @@ -84,7 +86,8 @@ export function TimelineMinimap({ currentIndex !== null && currentIndex >= 0 && currentIndex < items.length ? currentIndex : null; const previousItem = resolvedCurrentIndex === null ? null : (items[resolvedCurrentIndex - 1] ?? null); - const nextItem = resolvedCurrentIndex === null ? null : (items[resolvedCurrentIndex + 1] ?? null); + const nextItem = + resolvedCurrentIndex === null || atEnd ? null : (items[resolvedCurrentIndex + 1] ?? null); const resolveActiveIndexFromPointer = (event: MouseEvent) => { const rect = event.currentTarget.getBoundingClientRect(); From 2daf771a7b4673bc54b13e7eb0aab66de35ac5cc Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 8 Nov 2026 18:24:42 +0000 Subject: [PATCH 3/7] fix(web): minimap next turn stays enabled until the exact bottom The follow re-arm zone is 40px, and Next can still scroll inside it. AI-assisted; verified with the tests and tools listed above. --- .../src/components/chat/MessagesTimeline.browser.test.tsx | 3 +++ apps/web/src/components/chat/MessagesTimeline.tsx | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx b/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx index 94b6e0f47f9c4..9c610b61b7d6a 100644 --- a/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx +++ b/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx @@ -460,6 +460,9 @@ describe("MessagesTimeline messages", () => { }); expect(screen.button("Next turn")).toBeDisabled(); + + viewport.scrollTop -= 30; + await vi.waitFor(() => expect(screen.button("Next turn")).not.toBeDisabled()); }); it("keeps rows in item order after a reload or thread switch, before any timer runs", async () => { diff --git a/apps/web/src/components/chat/MessagesTimeline.tsx b/apps/web/src/components/chat/MessagesTimeline.tsx index 96e06c6912773..88a1e06e300ec 100644 --- a/apps/web/src/components/chat/MessagesTimeline.tsx +++ b/apps/web/src/components/chat/MessagesTimeline.tsx @@ -890,7 +890,11 @@ const ConversationTimeline = memo(function ConversationTimeline({ setMinimapCurrentIndex((current) => current === nextCurrentIndex ? current : nextCurrentIndex, ); - setMinimapAtEnd(resolveTimelineIsAtEnd(state) ?? false); + // The exact bottom, not the follow re-arm zone: Next can still scroll inside that zone. + setMinimapAtEnd( + viewport !== undefined && + viewport.scrollHeight - viewport.scrollTop - viewport.clientHeight <= 1, + ); }); const minimapRefreshFrameRef = useRef(null); From e48c6aad62f0bf4a18a3fab73d6735d7d9bf63f8 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 8 Nov 2026 18:29:50 +0000 Subject: [PATCH 4/7] fix(web): minimap refreshes when a thread's scroll position is restored A thread switch could keep the previous thread's at-bottom state and leave Next turn disabled mid-history until the next scroll. AI-assisted; verified with the tests and tools listed above. --- .../chat/MessagesTimeline.browser.test.tsx | 41 +++++++++++ .../src/components/chat/MessagesTimeline.tsx | 71 ++++++++++--------- 2 files changed, 79 insertions(+), 33 deletions(-) diff --git a/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx b/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx index 9c610b61b7d6a..a905a87afd7be 100644 --- a/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx +++ b/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx @@ -465,6 +465,47 @@ describe("MessagesTimeline messages", () => { await vi.waitFor(() => expect(screen.button("Next turn")).not.toBeDisabled()); }); + it("enables the minimap's next turn button on a thread restored above its bottom", async () => { + setup(); + const base = baseProps(); + const turns = (prefix: string) => + Array.from({ length: 16 }, (_, index) => [ + message(`${prefix} question ${index}`, {}, `${prefix}-user-${index}`), + message(`${prefix} answer ${index}`, { role: "assistant" }, `${prefix}-assistant-${index}`), + ]).flat(); + const other = "environment-local:thread-minimap-restored"; + rememberTimelinePosition( + other, + { rowId: "entry-b-user-4", offsetWithinRow: 0, scrollOffset: 0, atEnd: false }, + false, + ); + await using screen = await renderElement( + , + ); + const viewport = base.listRef.current!.getScrollableNode()!; + await vi.waitFor(() => { + expect(viewport.scrollTop).toBeGreaterThan(0); + expect(screen.button("Next turn")).toBeDisabled(); + }); + + await screen.rerender( + , + ); + await vi.waitFor(() => { + const row = screen.container.querySelector('[data-timeline-row-id="entry-b-user-4"]'); + expect(row).not.toBeNull(); + expect( + Math.abs(row!.getBoundingClientRect().top - viewport.getBoundingClientRect().top), + ).toBeLessThanOrEqual(2); + expect(screen.button("Next turn")).not.toBeDisabled(); + }); + }); + it("keeps rows in item order after a reload or thread switch, before any timer runs", async () => { setup(); // NVDA's browse mode keeps the first DOM order it reads, so a timer that sorts rows later is too late. diff --git a/apps/web/src/components/chat/MessagesTimeline.tsx b/apps/web/src/components/chat/MessagesTimeline.tsx index 88a1e06e300ec..7e1ccf276b874 100644 --- a/apps/web/src/components/chat/MessagesTimeline.tsx +++ b/apps/web/src/components/chat/MessagesTimeline.tsx @@ -732,37 +732,6 @@ const ConversationTimeline = memo(function ConversationTimeline({ const viewportRef = useRef(null); const navigateTimeline = () => viewportRef.current?.navigate({ releasesFollow: true }); const restoreReady = restoringThreadPosition && rows.length > 0; - // Z: syncs LegendList's scroll position with which thread it shows. The list - // is not keyed per thread and reports no "new data" event, and the restore - // must land before paint, after LegendList's own layout effects applied the - // new data. A citation request that arrives mid-restore takes over. - const { findOpenAtOpening } = identityChanged ? { findOpenAtOpening: findOpen } : listState; - // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- restores LegendList's scroll position for the shown thread before paint, after the list's own layout - useLayoutEffect(() => { - const list = listRef.current; - const viewport = viewportRef.current; - if (!restoreReady || !list || !viewport) return; - return startTimelinePositionRestore({ - list, - viewport, - listIdentityKey, - listOpenedOn, - rememberedPosition, - citationPending: citationRequest !== null, - releaseForFind: findOpenAtOpening, - onPositioned: setPositionedThreadKey, - }); - }, [ - citationRequest, - findOpenAtOpening, - listIdentityKey, - listOpenedOn, - listRef, - rememberedPosition, - restoreReady, - viewportRef, - ]); - const [timelineViewportElement, setTimelineViewportElement] = useState( null, ); @@ -898,14 +867,50 @@ const ConversationTimeline = memo(function ConversationTimeline({ }); const minimapRefreshFrameRef = useRef(null); - const scheduleMinimapRefresh = () => { + const scheduleMinimapRefresh = useStableCallback(() => { if (minimapRefreshFrameRef.current !== null) return; // LegendList recycles row containers before React commits their positions. minimapRefreshFrameRef.current = requestAnimationFrame(() => { minimapRefreshFrameRef.current = null; refreshMinimap(); }); - }; + }); + + // Z: syncs LegendList's scroll position with which thread it shows. The list + // is not keyed per thread and reports no "new data" event, and the restore + // must land before paint, after LegendList's own layout effects applied the + // new data. A citation request that arrives mid-restore takes over. + const { findOpenAtOpening } = identityChanged ? { findOpenAtOpening: findOpen } : listState; + // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- restores LegendList's scroll position for the shown thread before paint, after the list's own layout + useLayoutEffect(() => { + const list = listRef.current; + const viewport = viewportRef.current; + if (!restoreReady || !list || !viewport) return; + return startTimelinePositionRestore({ + list, + viewport, + listIdentityKey, + listOpenedOn, + rememberedPosition, + citationPending: citationRequest !== null, + releaseForFind: findOpenAtOpening, + onPositioned: (key) => { + setPositionedThreadKey(key); + // The restore can land without a scroll event, and the minimap skipped refreshes while it ran. + scheduleMinimapRefresh(); + }, + }); + }, [ + citationRequest, + findOpenAtOpening, + listIdentityKey, + listOpenedOn, + listRef, + rememberedPosition, + restoreReady, + scheduleMinimapRefresh, + viewportRef, + ]); // The measurement the last remember wrote, so a follow release can rewrite // it without reading render state from a listener. From 936834b69fae2a211b0abc477f91326c4aac7d5c Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 10 Nov 2026 09:29:09 +0000 Subject: [PATCH 5/7] fix(web): minimap next turn re-enables when a detached viewport shrinks The at-bottom state was only refreshed on scroll and content size changes, so shrinking the viewport while detached left Next disabled 600px above the bottom. The viewport resize observer now schedules a minimap refresh too. Co-Authored-By: Claude Opus 5.5 --- .../chat/MessagesTimeline.browser.test.tsx | 14 ++++++++++++++ apps/web/src/components/chat/MessagesTimeline.tsx | 7 ++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx b/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx index 2503551373e38..ddb0df6de5eb3 100644 --- a/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx +++ b/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx @@ -498,6 +498,20 @@ describe("MessagesTimeline messages", () => { viewport.scrollTop -= 30; await vi.waitFor(() => expect(screen.button("Next turn")).not.toBeDisabled()); + + // Shrinking a detached viewport moves the bottom away without a scroll event. + await screen.rerender( + , + ); + viewport.scrollTop = viewport.scrollHeight; + await vi.waitFor(() => expect(screen.button("Next turn")).toBeDisabled()); + screen.container.style.height = "600px"; + await vi.waitFor(() => { + expect(viewport.scrollHeight - viewport.clientHeight - viewport.scrollTop).toBeGreaterThan( + 500, + ); + expect(screen.button("Next turn")).not.toBeDisabled(); + }); }); it("enables the minimap's next turn button on a thread restored above its bottom", async () => { diff --git a/apps/web/src/components/chat/MessagesTimeline.tsx b/apps/web/src/components/chat/MessagesTimeline.tsx index c7137f068dabf..e71dfd7bb862f 100644 --- a/apps/web/src/components/chat/MessagesTimeline.tsx +++ b/apps/web/src/components/chat/MessagesTimeline.tsx @@ -981,9 +981,10 @@ const ConversationTimeline = memo(function ConversationTimeline({ const attachTimelineViewportElement = (viewportElement: HTMLDivElement | null) => { setTimelineViewportElement(viewportElement); if (!viewportElement) return; - const stopObserving = observeResize(viewportElement, () => - measureTimelineGutter(viewportElement), - ); + const stopObserving = observeResize(viewportElement, () => { + measureTimelineGutter(viewportElement); + scheduleMinimapRefresh(); + }); return () => { stopObserving(); setTimelineViewportElement(null); From ddd10150096d5ce6156c4a6153ad314e95f64aec Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 10 Nov 2026 10:47:09 +0000 Subject: [PATCH 6/7] fix(web): minimap next turn re-enables when the footer grows below a detached bottom LegendList keeps the footer size out of totalSize, so a growing footer moved the bottom away with no scroll or item size change. onMetricsChange now schedules a minimap refresh too. Co-Authored-By: Claude Opus 5.5 --- .../chat/MessagesTimeline.browser.test.tsx | 18 ++++++++++++++++++ .../src/components/chat/MessagesTimeline.tsx | 1 + 2 files changed, 19 insertions(+) diff --git a/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx b/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx index ddb0df6de5eb3..29fdcccd9c172 100644 --- a/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx +++ b/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx @@ -512,6 +512,24 @@ describe("MessagesTimeline messages", () => { ); expect(screen.button("Next turn")).not.toBeDisabled(); }); + + // So does a footer that grows below a detached bottom. + viewport.scrollTop = viewport.scrollHeight; + await vi.waitFor(() => expect(screen.button("Next turn")).toBeDisabled()); + await screen.rerender( + } + />, + ); + await vi.waitFor(() => { + expect(viewport.scrollHeight - viewport.clientHeight - viewport.scrollTop).toBeGreaterThan( + 300, + ); + expect(screen.button("Next turn")).not.toBeDisabled(); + }); }); it("enables the minimap's next turn button on a thread restored above its bottom", async () => { diff --git a/apps/web/src/components/chat/MessagesTimeline.tsx b/apps/web/src/components/chat/MessagesTimeline.tsx index e71dfd7bb862f..44ca39b1255cc 100644 --- a/apps/web/src/components/chat/MessagesTimeline.tsx +++ b/apps/web/src/components/chat/MessagesTimeline.tsx @@ -1335,6 +1335,7 @@ const ConversationTimeline = memo(function ConversationTimeline({ maintainScrollAtEndThreshold={1} onScroll={handleScroll} onItemSizeChanged={scheduleMinimapRefresh} + onMetricsChange={scheduleMinimapRefresh} className={cn( "messages-timeline-scroll scrollbar-gutter-both h-full min-h-0 overflow-x-hidden overscroll-y-contain [overflow-anchor:none]", topFadeEnabled && "topbar-scroll-fade", From e9f6a92157a8a709c1c1e78dfaf0f08e1f5bfacf Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 10 Nov 2026 11:32:04 +0000 Subject: [PATCH 7/7] fix(web): minimap refreshes after the restored position commits A refresh already queued when the restore finished ran before positionedThreadKey committed, returned at the restore guard, and left Next stale. A layout effect on the committed restore state now schedules it, so the restore effect goes back where main has it. Co-Authored-By: Claude Opus 5.5 --- .../src/components/chat/MessagesTimeline.tsx | 68 +++++++++---------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/apps/web/src/components/chat/MessagesTimeline.tsx b/apps/web/src/components/chat/MessagesTimeline.tsx index 44ca39b1255cc..02c5f153961b2 100644 --- a/apps/web/src/components/chat/MessagesTimeline.tsx +++ b/apps/web/src/components/chat/MessagesTimeline.tsx @@ -708,6 +708,37 @@ const ConversationTimeline = memo(function ConversationTimeline({ const viewportRef = useRef(null); const navigateTimeline = () => viewportRef.current?.navigate({ releasesFollow: true }); const restoreReady = restoringThreadPosition && rows.length > 0; + // Z: syncs LegendList's scroll position with which thread it shows. The list + // is not keyed per thread and reports no "new data" event, and the restore + // must land before paint, after LegendList's own layout effects applied the + // new data. A citation request that arrives mid-restore takes over. + const { findOpenAtOpening } = identityChanged ? { findOpenAtOpening: findOpen } : listState; + // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- restores LegendList's scroll position for the shown thread before paint, after the list's own layout + useLayoutEffect(() => { + const list = listRef.current; + const viewport = viewportRef.current; + if (!restoreReady || !list || !viewport) return; + return startTimelinePositionRestore({ + list, + viewport, + listIdentityKey, + listOpenedOn, + rememberedPosition, + citationPending: citationRequest !== null, + releaseForFind: findOpenAtOpening, + onPositioned: setPositionedThreadKey, + }); + }, [ + citationRequest, + findOpenAtOpening, + listIdentityKey, + listOpenedOn, + listRef, + rememberedPosition, + restoreReady, + viewportRef, + ]); + const [timelineViewportElement, setTimelineViewportElement] = useState( null, ); @@ -851,41 +882,10 @@ const ConversationTimeline = memo(function ConversationTimeline({ }); }); - // Z: syncs LegendList's scroll position with which thread it shows. The list - // is not keyed per thread and reports no "new data" event, and the restore - // must land before paint, after LegendList's own layout effects applied the - // new data. A citation request that arrives mid-restore takes over. - const { findOpenAtOpening } = identityChanged ? { findOpenAtOpening: findOpen } : listState; - // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- restores LegendList's scroll position for the shown thread before paint, after the list's own layout + // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- the minimap skips refreshes until the restore commits, and the restore can land without a scroll event useLayoutEffect(() => { - const list = listRef.current; - const viewport = viewportRef.current; - if (!restoreReady || !list || !viewport) return; - return startTimelinePositionRestore({ - list, - viewport, - listIdentityKey, - listOpenedOn, - rememberedPosition, - citationPending: citationRequest !== null, - releaseForFind: findOpenAtOpening, - onPositioned: (key) => { - setPositionedThreadKey(key); - // The restore can land without a scroll event, and the minimap skipped refreshes while it ran. - scheduleMinimapRefresh(); - }, - }); - }, [ - citationRequest, - findOpenAtOpening, - listIdentityKey, - listOpenedOn, - listRef, - rememberedPosition, - restoreReady, - scheduleMinimapRefresh, - viewportRef, - ]); + if (!restoringThreadPosition) scheduleMinimapRefresh(); + }, [restoringThreadPosition, scheduleMinimapRefresh]); // The measurement the last remember wrote, so a follow release can rewrite // it without reading render state from a listener.