@devries-cameron20 / t3code Mirror · read-only / commits / 57d5e98272
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 00:45 UTC

fix(web): minimap next turn is disabled at the bottom of a thread (#33038)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Nov 10, 2026 at 06:15 UTC 57d5e982728ee5e4bd85a2a7f4eac7e449d592cc
3 files changed +127 -6
apps/web/src/components/chat/MessagesTimeline.browser.test.tsx
+104
@@ -469,6 +469,110 @@ describe("MessagesTimeline messages", () => {
469 await expectHeadingInView("Last turn", "Turn 118:");
470 });
471
472 + it("disables the minimap's next turn button at the bottom of the thread", async () => {
473 + setup();
474 + const props = baseProps();
475 + const entries = Array.from({ length: 16 }, (_, index) => [
476 + message(`Question ${index}`, {}, `user-${index}`),
477 + message(`Answer ${index}`, { role: "assistant" }, `assistant-${index}`),
478 + ]).flat();
479 + await using screen = await renderTimeline(entries, props);
480 + const viewport = props.listRef.current!.getScrollableNode()!;
481 + const strips = () => [
482 + ...screen.container.querySelectorAll<HTMLElement>("[data-minimap-strip]"),
483 + ];
484 + // Several final turns share the last screen, so the current turn is not the last one.
485 + await vi.waitFor(() => {
486 + expect(viewport.scrollTop).toBeGreaterThan(0);
487 + expect(viewport.scrollHeight - viewport.clientHeight - viewport.scrollTop).toBeLessThan(2);
488 + expect(strips()[0]?.dataset.inView).toBe("false");
489 + expect(
490 + strips()
491 + .slice(-2)
492 + .map((strip) => strip.dataset.inView),
493 + ).toEqual(["true", "true"]);
494 + expect(screen.button("Previous turn")).not.toBeDisabled();
495 + });
496 +
497 + expect(screen.button("Next turn")).toBeDisabled();
498 +
499 + viewport.scrollTop -= 30;
500 + await vi.waitFor(() => expect(screen.button("Next turn")).not.toBeDisabled());
501 +
502 + // Shrinking a detached viewport moves the bottom away without a scroll event.
503 + await screen.rerender(
504 + <MessagesTimeline {...props} timelineEntries={entries} liveFollowEnabled={false} />,
505 + );
506 + viewport.scrollTop = viewport.scrollHeight;
507 + await vi.waitFor(() => expect(screen.button("Next turn")).toBeDisabled());
508 + screen.container.style.height = "600px";
509 + await vi.waitFor(() => {
510 + expect(viewport.scrollHeight - viewport.clientHeight - viewport.scrollTop).toBeGreaterThan(
511 + 500,
512 + );
513 + expect(screen.button("Next turn")).not.toBeDisabled();
514 + });
515 +
516 + // So does a footer that grows below a detached bottom.
517 + viewport.scrollTop = viewport.scrollHeight;
518 + await vi.waitFor(() => expect(screen.button("Next turn")).toBeDisabled());
519 + await screen.rerender(
520 + <MessagesTimeline
521 + {...props}
522 + timelineEntries={entries}
523 + liveFollowEnabled={false}
524 + footer={<div style={{ height: 400 }} />}
525 + />,
526 + );
527 + await vi.waitFor(() => {
528 + expect(viewport.scrollHeight - viewport.clientHeight - viewport.scrollTop).toBeGreaterThan(
529 + 300,
530 + );
531 + expect(screen.button("Next turn")).not.toBeDisabled();
532 + });
533 + });
534 +
535 + it("enables the minimap's next turn button on a thread restored above its bottom", async () => {
536 + setup();
537 + const base = baseProps();
538 + const turns = (prefix: string) =>
539 + Array.from({ length: 16 }, (_, index) => [
540 + message(`${prefix} question ${index}`, {}, `${prefix}-user-${index}`),
541 + message(`${prefix} answer ${index}`, { role: "assistant" }, `${prefix}-assistant-${index}`),
542 + ]).flat();
543 + const other = "environment-local:thread-minimap-restored";
544 + rememberTimelinePosition(
545 + other,
546 + { rowId: "entry-b-user-4", offsetWithinRow: 0, scrollOffset: 0, atEnd: false },
547 + false,
548 + );
549 + await using screen = await renderElement(
550 + <MessagesTimeline {...base} timelineEntries={turns("a")} />,
551 + );
552 + const viewport = base.listRef.current!.getScrollableNode()!;
553 + await vi.waitFor(() => {
554 + expect(viewport.scrollTop).toBeGreaterThan(0);
555 + expect(screen.button("Next turn")).toBeDisabled();
556 + });
557 +
558 + await screen.rerender(
559 + <MessagesTimeline
560 + {...base}
561 + routeThreadKey={other}
562 + timelineEntries={turns("b")}
563 + liveFollowEnabled={false}
564 + />,
565 + );
566 + await vi.waitFor(() => {
567 + const row = screen.container.querySelector('[data-timeline-row-id="entry-b-user-4"]');
568 + expect(row).not.toBeNull();
569 + expect(
570 + Math.abs(row!.getBoundingClientRect().top - viewport.getBoundingClientRect().top),
571 + ).toBeLessThanOrEqual(2);
572 + expect(screen.button("Next turn")).not.toBeDisabled();
573 + });
574 + });
575 +
576 it("keeps rows in item order after a reload or thread switch, before any timer runs", async () => {
577 setup();
578 // NVDA's browse mode keeps the first DOM order it reads, so a timer that sorts rows later is too late.
apps/web/src/components/chat/MessagesTimeline.tsx
+19 -5
@@ -794,6 +794,7 @@ const ConversationTimeline = memo(function ConversationTimeline({
794 };
795 const [minimapHitStripWidth, setMinimapHitStripWidth] = useState(0);
796 const [minimapCurrentIndex, setMinimapCurrentIndex] = useState<number | null>(null);
797 + const [minimapAtEnd, setMinimapAtEnd] = useState(false);
798 const handleAnchorReady = (info: { anchorIndex: number | undefined }) => {
799 if (anchorMessageId !== null && info.anchorIndex !== undefined) {
800 onAnchorReady(anchorMessageId, info.anchorIndex);
@@ -864,17 +865,27 @@ const ConversationTimeline = memo(function ConversationTimeline({
865 setMinimapCurrentIndex((current) =>
866 current === nextCurrentIndex ? current : nextCurrentIndex,
867 );
868 + // The exact bottom, not the follow re-arm zone: Next can still scroll inside that zone.
869 + setMinimapAtEnd(
870 + viewport !== undefined &&
871 + viewport.scrollHeight - viewport.scrollTop - viewport.clientHeight <= 1,
872 + );
873 });
874
875 const minimapRefreshFrameRef = useRef<number | null>(null);
870 - const scheduleMinimapRefresh = () => {
876 + const scheduleMinimapRefresh = useStableCallback(() => {
877 if (minimapRefreshFrameRef.current !== null) return;
878 // LegendList recycles row containers before React commits their positions.
879 minimapRefreshFrameRef.current = requestAnimationFrame(() => {
880 minimapRefreshFrameRef.current = null;
881 refreshMinimap();
882 });
877 - };
883 + });
884 +
885 + // 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
886 + useLayoutEffect(() => {
887 + if (!restoringThreadPosition) scheduleMinimapRefresh();
888 + }, [restoringThreadPosition, scheduleMinimapRefresh]);
889
890 // The measurement the last remember wrote, so a follow release can rewrite
891 // it without reading render state from a listener.
@@ -970,9 +981,10 @@ const ConversationTimeline = memo(function ConversationTimeline({
981 const attachTimelineViewportElement = (viewportElement: HTMLDivElement | null) => {
982 setTimelineViewportElement(viewportElement);
983 if (!viewportElement) return;
973 - const stopObserving = observeResize(viewportElement, () =>
974 - measureTimelineGutter(viewportElement),
975 - );
984 + const stopObserving = observeResize(viewportElement, () => {
985 + measureTimelineGutter(viewportElement);
986 + scheduleMinimapRefresh();
987 + });
988 return () => {
989 stopObserving();
990 setTimelineViewportElement(null);
@@ -1323,6 +1335,7 @@ const ConversationTimeline = memo(function ConversationTimeline({
1335 maintainScrollAtEndThreshold={1}
1336 onScroll={handleScroll}
1337 onItemSizeChanged={scheduleMinimapRefresh}
1338 + onMetricsChange={scheduleMinimapRefresh}
1339 className={cn(
1340 "messages-timeline-scroll scrollbar-gutter-both h-full min-h-0 overflow-x-hidden overscroll-y-contain [overflow-anchor:none]",
1341 topFadeEnabled && "topbar-scroll-fade",
@@ -1335,6 +1348,7 @@ const ConversationTimeline = memo(function ConversationTimeline({
1348 hasPersistentGutter={minimapHasPersistentGutter}
1349 hitStripWidth={minimapHitStripWidth}
1350 currentIndex={minimapCurrentIndex}
1351 + atEnd={minimapAtEnd}
1352 stripMap={minimapStripMap}
1353 onWheel={forwardMinimapWheel}
1354 onSelect={(item) => {
apps/web/src/components/chat/TimelineMinimap.tsx
+4 -1
@@ -38,6 +38,7 @@ export function TimelineMinimap({
38 hasPersistentGutter,
39 hitStripWidth,
40 currentIndex,
41 + atEnd,
42 items,
43 stripMap,
44 onWheel,
@@ -46,6 +47,7 @@ export function TimelineMinimap({
47 hasPersistentGutter: boolean;
48 hitStripWidth: number;
49 currentIndex: number | null;
50 + atEnd: boolean;
51 items: ReadonlyArray<TimelineMinimapItem>;
52 stripMap: Map<string, HTMLSpanElement>;
53 onWheel: (event: WheelEvent) => void;
@@ -84,7 +86,8 @@ export function TimelineMinimap({
86 currentIndex !== null && currentIndex >= 0 && currentIndex < items.length ? currentIndex : null;
87 const previousItem =
88 resolvedCurrentIndex === null ? null : (items[resolvedCurrentIndex - 1] ?? null);
87 - const nextItem = resolvedCurrentIndex === null ? null : (items[resolvedCurrentIndex + 1] ?? null);
89 + const nextItem =
90 + resolvedCurrentIndex === null || atEnd ? null : (items[resolvedCurrentIndex + 1] ?? null);
91
92 const resolveActiveIndexFromPointer = (event: MouseEvent<HTMLElement>) => {
93 const rect = event.currentTarget.getBoundingClientRect();