Skip to content

Commit c99201c

Browse files
fix(web): minimap Next turn no longer sticks on adjacent user messages (#33036)
1 parent ac1cb92 commit c99201c

3 files changed

Lines changed: 57 additions & 3 deletions

File tree

‎apps/web/src/components/chat/MessagesTimeline.browser.test.tsx‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,50 @@ describe("MessagesTimeline messages", () => {
763763
expect(turns).toEqual(turns.toSorted((a, b) => a - b));
764764
});
765765

766+
it("steps the minimap's next turn past two adjacent user messages", async () => {
767+
const props = baseProps();
768+
const reply = (id: string) => message("Reply.\n\n".repeat(120), { role: "assistant" }, id);
769+
const userIds = ["turn-0", "turn-1", "turn-2", "pair-a", "pair-b", "turn-3", "turn-4"];
770+
const entries = [
771+
...["turn-0", "turn-1", "turn-2"].flatMap((id) => [message(id, {}, id), reply(`${id}-r`)]),
772+
message("pair-a", {}, "pair-a"),
773+
message("pair-b", {}, "pair-b"),
774+
reply("pair-b-r"),
775+
...["turn-3", "turn-4"].flatMap((id) => [message(id, {}, id), reply(`${id}-r`)]),
776+
];
777+
const session = cdp();
778+
await session.send("Emulation.setEmulatedMedia", {
779+
features: [{ name: "prefers-reduced-motion", value: "reduce" }],
780+
});
781+
try {
782+
await using screen = await renderTimeline(entries, props);
783+
const viewport = props.listRef.current!.getScrollableNode()!;
784+
const strips = () => [...screen.container.querySelectorAll("[data-minimap-strip]")];
785+
const turnAtTop = () =>
786+
userIds.find((id) => {
787+
const row = screen.container.querySelector(`[data-message-id="${id}"]`);
788+
if (!row) return false;
789+
const offset = row.getBoundingClientRect().top - viewport.getBoundingClientRect().top;
790+
return offset >= 0 && offset < 100;
791+
});
792+
await act(() => {
793+
void props.listRef.current!.scrollToIndex({ index: 0, animated: false });
794+
});
795+
await vi.waitFor(() => expect(strips()[0]?.getAttribute("data-in-view")).toBe("true"));
796+
797+
// Clicks again while the view has not moved, as a user would.
798+
for (const id of userIds.slice(1)) {
799+
const from = turnAtTop();
800+
await vi.waitFor(async () => {
801+
if (turnAtTop() === from) await click(screen.button("Next turn"));
802+
expect(turnAtTop(), "turn at the top after Next turn").toBe(id);
803+
});
804+
}
805+
} finally {
806+
await session.send("Emulation.setEmulatedMedia", { features: [] });
807+
}
808+
});
809+
766810
it("preserves XML-like tags and comparisons in user messages as text", async () => {
767811
const source = [
768812
'Without reading a file, do you have <global-agent-instructions scope="workspace">',

‎apps/web/src/components/chat/MessagesTimeline.logic.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ export function workEntryIsVisibleInGroup(
280280
}
281281
const TIMELINE_MINIMAP_ITEM_SPACING = 8;
282282
export const TIMELINE_MINIMAP_MIN_ITEMS = 2;
283+
export const TIMELINE_MINIMAP_TARGET_OFFSET = 24;
283284
// Relative to the timeline, not the viewport, so an open terminal shrinks the rail and
284285
// endpoint previews (centered on their strip) still fit above and below it.
285286
const TIMELINE_MINIMAP_MAX_HEIGHT_CSS = "max(4rem, calc(100% - 14.75rem))";

‎apps/web/src/components/chat/MessagesTimeline.tsx‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ import {
8484
isTimelineMinimapRowVisible,
8585
resolveTimelineMinimapVisibleRange,
8686
resolveTimelineMinimapHitStripWidth,
87+
TIMELINE_MINIMAP_TARGET_OFFSET,
8788
timelineTurnFoldRunIdsByEntryId,
8889
liveAnswerPreview,
8990
type MessagesTimelineRow,
@@ -944,9 +945,17 @@ const ConversationTimeline = memo(function ConversationTimeline({
944945
strip.dataset.inView = next;
945946
}
946947
}
948+
// Ignore rows ending within the offset minimap navigation leaves above its target, or
949+
// Next turn keeps retargeting the same row. 1px absorbs device-pixel scroll rounding.
950+
const currentInset = TIMELINE_MINIMAP_TARGET_OFFSET + 1;
951+
const currentRange = resolveTimelineMinimapVisibleRange({
952+
...state,
953+
scroll: scroll + currentInset,
954+
scrollLength: state.scrollLength - currentInset,
955+
});
947956
const nextCurrentIndex = resolveTimelineMinimapCurrentIndex({
948-
visibleStart: visibleRange.start,
949-
visibleEnd: visibleRange.end,
957+
visibleStart: currentRange.start,
958+
visibleEnd: currentRange.end,
950959
rowIndices: minimapRowIndices,
951960
});
952961
setMinimapCurrentIndex((current) =>
@@ -1479,7 +1488,7 @@ const ConversationTimeline = memo(function ConversationTimeline({
14791488
void listRef.current?.scrollToIndex({
14801489
index: item.rowIndex,
14811490
animated: !window.matchMedia("(prefers-reduced-motion: reduce)").matches,
1482-
viewOffset: 24,
1491+
viewOffset: TIMELINE_MINIMAP_TARGET_OFFSET,
14831492
});
14841493
}}
14851494
/>

0 commit comments

Comments
 (0)