The best way to control Claude Code, Codex and more from any computer or phone
fix(web): threads open at the newest message, not thousands of pixels above it (#19663)
Co-authored-by: Aaron Queen <bompus@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Theo Browne committed
Oct 19, 2026 at 11:07 UTC
a0fd2063868d16a9ae11adf45e4f0c36bd27b4b0
2 files changed
+106
-2
apps/web/src/components/chat/MessagesTimeline.browser.test.tsx
+87
-1
@@ -930,6 +930,72 @@ describe("MessagesTimeline history and thread links", () => {
930
expect(onOpenThread).toHaveBeenCalledWith("thread-parent");
931
});
932
933
+ it("opens a thread at its newest message after an empty pane and restores it on return", async () => {
934
+ const props = baseProps();
935
+ const entries = Array.from({ length: 12 }, (_, index) =>
936
+ message(
937
+ Array.from({ length: 60 }, (_, line) => `Paragraph ${index}.${line}`).join("\n\n"),
938
+ { role: "assistant" },
939
+ `message-${index}`,
940
+ ),
941
+ );
942
+ await renderTimeline([], {
943
+ ...props,
944
+ routeThreadKey: `${props.routeThreadKey}-loading`,
945
+ hideEmptyPlaceholder: true,
946
+ });
947
+
948
+ // Each row is much taller than LegendList's estimate.
949
+ await act(async () =>
950
+ roots.at(-1)!.render(<MessagesTimeline {...props} timelineEntries={entries} />),
951
+ );
952
+ const viewport = props.listRef.current!.getScrollableNode();
953
+ await vi.waitFor(() => {
954
+ expect(viewport.scrollHeight).toBeGreaterThan(viewport.clientHeight);
955
+ expect(text()).toContain("Paragraph 11.59");
956
+ expect(
957
+ viewport.scrollHeight - viewport.clientHeight - viewport.scrollTop,
958
+ ).toBeLessThanOrEqual(1);
959
+ });
960
+
961
+ const otherThreadKey = `${props.routeThreadKey}-other`;
962
+ await act(async () =>
963
+ roots
964
+ .at(-1)!
965
+ .render(
966
+ <MessagesTimeline
967
+ {...props}
968
+ routeThreadKey={otherThreadKey}
969
+ timelineEntries={entries}
970
+ liveFollowEnabled={false}
971
+ />,
972
+ ),
973
+ );
974
+ await vi.waitFor(() =>
975
+ expect(
976
+ viewport.scrollHeight - viewport.clientHeight - viewport.scrollTop,
977
+ ).toBeLessThanOrEqual(1),
978
+ );
979
+ // Move beyond LegendList's one-viewport follow threshold so it cannot mask restoration.
980
+ await userEvent.wheel(viewport, { delta: { y: -2000 } });
981
+ await vi.waitFor(() => {
982
+ expect(readTimelinePosition(otherThreadKey)?.atEnd).toBe(false);
983
+ expect(viewport.scrollHeight - viewport.clientHeight - viewport.scrollTop).toBeGreaterThan(
984
+ viewport.clientHeight,
985
+ );
986
+ });
987
+
988
+ await act(async () =>
989
+ roots.at(-1)!.render(<MessagesTimeline {...props} timelineEntries={entries} />),
990
+ );
991
+ await vi.waitFor(() => {
992
+ expect(text()).toContain("Paragraph 11.59");
993
+ expect(
994
+ viewport.scrollHeight - viewport.clientHeight - viewport.scrollTop,
995
+ ).toBeLessThanOrEqual(1);
996
+ });
997
+ });
998
+
999
it("does not render the transient V2 interruption request", async () => {
1000
await renderTimeline([
1001
{
@@ -1299,7 +1365,7 @@ describe("MessagesTimeline scroll position", () => {
1365
expect(maxNestedCommits).toBeLessThan(8);
1366
});
1367
1302
- it("remembers a manual reading position when the chat closes", async () => {
1368
+ it("restores a manual reading position after reopening and switching threads", async () => {
1369
const props = baseProps();
1370
function Chat() {
1371
const [liveFollowEnabled, setLiveFollowEnabled] = useState(true);
@@ -1326,6 +1392,26 @@ describe("MessagesTimeline scroll position", () => {
1392
atEnd: false,
1393
scrollOffset: offset,
1394
});
1395
+
1396
+ const timeline = (routeThreadKey: string) => (
1397
+ <MessagesTimeline {...props} routeThreadKey={routeThreadKey} timelineEntries={tallEntries} />
1398
+ );
1399
+ await renderElement(timeline(props.routeThreadKey));
1400
+ const reopenedViewport = await waitForList(props);
1401
+ await vi.waitFor(() =>
1402
+ expect(Math.abs(reopenedViewport.scrollTop - offset)).toBeLessThanOrEqual(1),
1403
+ );
1404
+
1405
+ await act(async () => roots.at(-1)!.render(timeline(`${props.routeThreadKey}-other`)));
1406
+ await vi.waitFor(() =>
1407
+ expect(
1408
+ reopenedViewport.scrollHeight - reopenedViewport.clientHeight - reopenedViewport.scrollTop,
1409
+ ).toBeLessThanOrEqual(1),
1410
+ );
1411
+ await act(async () => roots.at(-1)!.render(timeline(props.routeThreadKey)));
1412
+ await vi.waitFor(() =>
1413
+ expect(Math.abs(reopenedViewport.scrollTop - offset)).toBeLessThanOrEqual(1),
1414
+ );
1415
});
1416
1417
it("restores the composer after closing tool output only at the end", async () => {
apps/web/src/components/chat/MessagesTimeline.tsx
+19
-1
@@ -862,6 +862,22 @@ const ConversationTimeline = memo(function ConversationTimeline({
862
// must not change with them or every timeline row re-renders per event.
863
const runs = useStableHandoffRuns(runsProp);
864
const minimapItems = deriveTimelineMinimapItems(rows);
865
+ // Preserve initialScrollAtEnd's measured target until the list is reused
866
+ // for another thread; scrollToEnd would replace it with an estimated offset.
867
+ const listOpenedOnRef = useRef<{
868
+ readonly list: LegendListRef;
869
+ identity: string | null;
870
+ } | null>(null);
871
+ useLayoutEffect(() => {
872
+ const list = listRef.current;
873
+ const opened = listOpenedOnRef.current;
874
+ if (!list) return;
875
+ if (opened?.list !== list) {
876
+ listOpenedOnRef.current = { list, identity: listIdentityKey };
877
+ } else if (opened.identity !== listIdentityKey) {
878
+ opened.identity = null;
879
+ }
880
+ });
881
const restoreRowIndex =
882
restoringThreadPosition && rememberedPosition?.atEnd === false
883
? rows.findIndex((row) => row.id === rememberedPosition.rowId)
@@ -919,7 +935,9 @@ const ConversationTimeline = memo(function ConversationTimeline({
935
viewOffset: -position.offsetWithinRow,
936
})
937
: list.scrollToOffset({ offset: position.scrollOffset, animated: false })
922
- : list.scrollToEnd({ animated: false });
938
+ : listOpenedOnRef.current?.identity === listIdentityKey
939
+ ? undefined
940
+ : list.scrollToEnd({ animated: false });
941
void Promise.resolve(scrolling).then(() => {
942
if (cancelled) return;
943
if (position?.atEnd !== false || index < 0) {