From df0126cae8dc3ccdb813f2c2158e8d9a5d56d42b Mon Sep 17 00:00:00 2001 From: Theo Browne Date: Wed, 28 Oct 2026 02:17:34 -0700 Subject: [PATCH] fix(web): scroll-to-end button no longer jumps up and down The timeline's list ref callback re-ran on every render. Its cleanup reported that the content fits for one frame, which flipped the resting composer, moved the button, and re-rendered the timeline again. A stable ref callback attaches the list once per mount. Co-Authored-By: Claude Opus 5.5 --- .../chat/MessagesTimeline.browser.test.tsx | 23 +++++++++++++++++++ .../src/components/chat/MessagesTimeline.tsx | 6 +++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx b/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx index 2c7aa332756cb..085fa23b2c49d 100644 --- a/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx +++ b/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx @@ -205,6 +205,29 @@ describe("MessagesTimeline messages", () => { expect(maxNestedCommits).toBeLessThan(20); }); + it("keeps reporting overflow while the composer inset changes", async () => { + setup(); + const props = baseProps(); + const overflowReports: boolean[] = []; + const replies = Array.from({ length: 40 }, (_, index) => + message(`Reply ${index}\n\n${"line\n\n".repeat(8)}`, { role: "assistant" }, `r-${index}`), + ); + const timeline = (inset: number) => ( + overflowReports.push(overflows)} + /> + ); + await using screen = await renderElement(timeline(110)); + await vi.waitFor(() => expect(overflowReports.at(-1)).toBe(true)); + overflowReports.length = 0; + // The resting composer resizes with overflow; a false report here flips it back. + await screen.rerender(timeline(148)); + expect(overflowReports).not.toContain(false); + }); + it("keeps the first and last message headings reachable from either end", async () => { setup(); const props = baseProps(); diff --git a/apps/web/src/components/chat/MessagesTimeline.tsx b/apps/web/src/components/chat/MessagesTimeline.tsx index c7a38de8fbed6..b74f9edd595c9 100644 --- a/apps/web/src/components/chat/MessagesTimeline.tsx +++ b/apps/web/src/components/chat/MessagesTimeline.tsx @@ -1144,7 +1144,9 @@ const ConversationTimeline = memo(function ConversationTimeline({ const canvas = useChatCanvas(); const registerTimeline = canvas?.registerTimeline; - const setTimelineList = (list: LegendListRef | null) => { + // Stable so the list attaches once per mount. A re-attach reports no overflow for a frame, + // which flips the resting composer, resizes it, and re-renders this list again. + const setTimelineList = useStableCallback((list: LegendListRef | null) => { listRef.current = list; const scrollNode: HTMLElement | null = list?.getScrollableNode() ?? null; registerTimeline?.(scrollNode); @@ -1190,7 +1192,7 @@ const ConversationTimeline = memo(function ConversationTimeline({ listRef.current = null; registerTimeline?.(null); }; - }; + }); useThreadFindPositionReader({ threadKey: listIdentityKey,