Skip to content
TypeScript

fix(web): scroll-to-end button no longer jumps up and down (#26375)

Theo Brownec677d5fc45e6
diff --git a/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx b/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx
index 2c7aa332756..085fa23b2c4 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) => (
+ <MessagesTimeline
+ {...props}
+ timelineEntries={replies}
+ contentInsetEndAdjustment={inset}
+ onContentOverflowChange={(overflows) => 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 c7a38de8fbe..b74f9edd595 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,