Skip to content

Commit bc7efe2

Browse files
t3dotggbompusclaude
committed
fix(web): threads opened from an empty pane land at the latest message
When the timeline list mounted fresh for a thread, the restore effect's scrollToEnd replaced LegendList's initialScrollAtEnd, which keeps retargeting the end while rows measure. The thread stopped at the estimated end, often thousands of pixels above the newest message. Skip that call when the list mounted for this thread. A list reused across a thread switch still scrolls to the end. Takes over #18074. Co-authored-by: Aaron Queen <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 16918b5 commit bc7efe2

2 files changed

Lines changed: 51 additions & 1 deletion

File tree

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,36 @@ describe("MessagesTimeline history and thread links", () => {
838838
expect(onOpenThread).toHaveBeenCalledWith("thread-parent");
839839
});
840840

841+
it("opens a thread at its newest message after an empty pane", async () => {
842+
const props = baseProps();
843+
const entries = Array.from({ length: 12 }, (_, index) =>
844+
message(
845+
Array.from({ length: 60 }, (_, line) => `Paragraph ${index}.${line}`).join("\n\n"),
846+
{ role: "assistant" },
847+
`message-${index}`,
848+
),
849+
);
850+
const timeline = (routeThreadKey: string, timelineEntries: Entry[]) => (
851+
<MessagesTimeline
852+
{...props}
853+
routeThreadKey={routeThreadKey}
854+
timelineEntries={timelineEntries}
855+
hideEmptyPlaceholder
856+
/>
857+
);
858+
await renderElement(timeline("environment-local:loading", []));
859+
860+
// The list mounts for this thread, with rows far taller than estimated.
861+
await act(async () => roots.at(-1)!.render(timeline("environment-local:opened", entries)));
862+
for (let frame = 0; frame < 20; frame += 1) {
863+
await act(() => new Promise((resolve) => requestAnimationFrame(resolve)));
864+
}
865+
const viewport = props.listRef.current!.getScrollableNode();
866+
expect(viewport.scrollHeight - viewport.clientHeight - viewport.scrollTop).toBeLessThanOrEqual(
867+
1,
868+
);
869+
});
870+
841871
it("does not render the transient V2 interruption request", async () => {
842872
await renderTimeline([
843873
{

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,24 @@ const ConversationTimeline = memo(function ConversationTimeline({
853853
// must not change with them or every timeline row re-renders per event.
854854
const runs = useStableHandoffRuns(runsProp);
855855
const minimapItems = deriveTimelineMinimapItems(rows);
856+
// The list instance and the thread it mounted on. That list's
857+
// initialScrollAtEnd keeps retargeting the end while rows measure, and an
858+
// imperative scrollToEnd would replace it with one that stops at the
859+
// estimated end. Once the list shows another thread, it is no longer fresh.
860+
const listOpenedOnRef = useRef<{
861+
readonly list: LegendListRef;
862+
readonly identity: string | null;
863+
} | null>(null);
864+
useLayoutEffect(() => {
865+
const list = listRef.current;
866+
const opened = listOpenedOnRef.current;
867+
if (!list) return;
868+
if (opened?.list !== list) {
869+
listOpenedOnRef.current = { list, identity: listIdentityKey };
870+
} else if (opened.identity !== listIdentityKey) {
871+
listOpenedOnRef.current = { list, identity: null };
872+
}
873+
});
856874
const restoreRowIndex =
857875
restoringThreadPosition && rememberedPosition?.atEnd === false
858876
? rows.findIndex((row) => row.id === rememberedPosition.rowId)
@@ -910,7 +928,9 @@ const ConversationTimeline = memo(function ConversationTimeline({
910928
viewOffset: -position.offsetWithinRow,
911929
})
912930
: list.scrollToOffset({ offset: position.scrollOffset, animated: false })
913-
: list.scrollToEnd({ animated: false });
931+
: listOpenedOnRef.current?.identity === listIdentityKey
932+
? undefined
933+
: list.scrollToEnd({ animated: false });
914934
void Promise.resolve(scrolling).then(() => {
915935
if (cancelled) return;
916936
if (position?.atEnd !== false || index < 0) {

0 commit comments

Comments
 (0)