Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
d68f920
fix(web): chat stays pinned when the terminal drawer opens during a turn
juliusmarminge Nov 8, 2026
096f18a
fix(web): chat stays pinned on every frame of a viewport resize durin…
juliusmarminge Nov 8, 2026
4c2d323
fix(web): chat keeps following a stream after the terminal drawer opens
juliusmarminge Nov 8, 2026
885285d
test(web): a queued resize pin is dropped once the reader scrolls away
juliusmarminge Nov 8, 2026
2b7127a
Merge remote-tracking branch 'origin/main' into fix/issue-32778
juliusmarminge Nov 8, 2026
8d610a1
Merge remote-tracking branch 'origin/main' into fix/issue-32778
juliusmarminge Nov 10, 2026
bc12eab
fix(web): opening the terminal mid-turn keeps the live end in view
juliusmarminge Nov 10, 2026
c6bff8b
fix(web): pin the end from Legend's onLayout so it sees the new viewport
juliusmarminge Nov 10, 2026
11f04de
fix(web): commit the resize pin before the frame paints
juliusmarminge Nov 10, 2026
c6b46f3
test(web): drop a before-paint check the test runtime cannot fail
juliusmarminge Nov 10, 2026
72eabe0
Merge remote-tracking branch 'origin/main' into pr-32826
juliusmarminge Nov 10, 2026
b28a234
Merge remote-tracking branch 'origin/main' into pr-32826
juliusmarminge Nov 10, 2026
f57ff76
fix(web): resize pin covers same-frame growth and the scroll-to-end s…
juliusmarminge Nov 10, 2026
8caf9c2
Merge remote-tracking branch 'origin/main' into pr-32826
juliusmarminge Nov 10, 2026
5ccdae6
Merge remote-tracking branch 'origin/main' into fix/issue-32778
juliusmarminge Nov 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions apps/web/src/components/chat/MessagesTimeline.browser.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import "~/index.css";

import { environmentThreadDetails } from "../../state/threads";
import { act, fakeTimers, render, stubGlobal } from "../../../test/render";
import { observeResize } from "~/lib/observeResize";
import { ChangedFilesCard } from "./ChangedFilesTree";
import { MessagesTimeline } from "./MessagesTimeline";
import { makeStreamingTimelineFixture } from "../../test-fixtures";
Expand Down Expand Up @@ -359,6 +360,90 @@ describe("MessagesTimeline work rows", () => {
await vi.waitFor(() => expect(distanceFromEnd()).toBeLessThan(2));
});

it("pins the live end at once when the viewport shrinks during a turn", async () => {
const props = { ...baseProps(), isWorking: true };
const runId = RunId.make("live-run");
const container = document.createElement("div");
container.style.cssText = "height: 600px; width: 900px; display: flex; flex-direction: column;";
const reply = (id: string) =>
message("Streamed reply\n\n".repeat(40), { role: "assistant", runId }, id);
const entries = [
...Array.from({ length: 12 }, (_, index) =>
message(`Earlier context ${index}`, {}, `context-${index}`),
),
reply("progress"),
];
// The app shell subscribes to the shared resize observer before any list mounts, so it is
// notified before Legend measures the new viewport.
const shell = document.body.appendChild(document.createElement("div"));
onTestFinished(() => shell.remove());
onTestFinished(observeResize(shell, () => {}));
await using screen = await render(<MessagesTimeline {...props} timelineEntries={entries} />, {
container,
});
const viewport = props.listRef.current!.getScrollableNode()!;
const distanceFromEnd = () =>
viewport.scrollHeight - viewport.clientHeight - viewport.scrollTop;
await vi.waitFor(() => expect(distanceFromEnd()).toBeLessThan(2));
using scrollTo = vi.spyOn(viewport, "scrollTo");
const pinnedEnd = (behavior: ScrollBehavior) =>
vi.waitFor(() => {
expect(scrollTo).toHaveBeenLastCalledWith(expect.objectContaining({ behavior }));
expect(distanceFromEnd()).toBeLessThan(2);
});

await screen.rerender(
<MessagesTimeline {...props} timelineEntries={[...entries, reply("first")]} />,
);
await vi.waitFor(() =>
expect(scrollTo).toHaveBeenCalledWith(expect.objectContaining({ behavior: "smooth" })),
);
// Shrinks by more than the new viewport while that smooth pin runs.
container.style.height = "200px";
await pinnedEnd("instant");

await screen.rerender(
<MessagesTimeline
{...props}
timelineEntries={[...entries, reply("first"), reply("second")]}
/>,
);
await pinnedEnd("smooth");

// Read after Legend's resize delivery and its microtasks, before the frame paints.
const distanceAfterResize = (height: string, change: () => void) =>
new Promise<number>((resolve) => {
const observer = new ResizeObserver(() => {
observer.disconnect();
resolve(distanceFromEnd());
});
observer.observe(viewport);
change();
container.style.height = height;
});
// The newest row grows in the same resize delivery.
const newestParagraph = screen.getByText("Streamed reply").last().element() as HTMLElement;
expect(
await distanceAfterResize("300px", () => (newestParagraph.style.paddingBottom = "191px")),
).toBeLessThan(2);
// The scroll-to-end settle's scrollToOffset clears Legend's follow while it runs.
expect(
await distanceAfterResize("250px", () => {
void props.listRef.current!.scrollToOffset({
offset: viewport.scrollHeight - viewport.clientHeight,
animated: false,
});
expect(props.listRef.current!.getState().isFollowingEnd).toBe(false);
}),
).toBeLessThan(2);

viewport.scrollTop = 0;
await vi.waitFor(() => expect(props.listRef.current!.getState().isFollowingEnd).toBe(false));
scrollTo.mockClear();
expect(await distanceAfterResize("500px", () => {})).toBeGreaterThan(500);
expect(scrollTo).not.toHaveBeenCalled();
});

it.each(["delegated", "legacy", "missing"] as const)(
"uses the reported task for %s completion notifications",
async (source) => {
Expand Down
49 changes: 38 additions & 11 deletions apps/web/src/components/chat/MessagesTimeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
import { parseScopedThreadKey } from "@t3tools/client-runtime/environment";
import { resolveWorkGroupScrollAnchor } from "@t3tools/client-runtime/work-log/scroll-anchor";
import type { WorkflowOpening } from "@t3tools/client-runtime/state/subagentRuntime";
import { flushSync } from "react-dom";
import { observeResize } from "~/lib/observeResize";
import { useStableCallback } from "~/hooks/useStableCallback";

Expand Down Expand Up @@ -978,6 +979,41 @@ const ConversationTimeline = memo(function ConversationTimeline({
if (viewportElement) measureTimelineGutter(viewportElement);
});
};
const maintainScrollAtEnd =
citationPositioning ||
(restoringThreadPosition && rememberedPosition?.atEnd === false) ||
anchoredEndSpace ||
!liveFollowEnabled ||
fullscreenAppRowId !== null
? false
: isWorking && !prefersReducedMotion && settlingListIdentity === null
? TIMELINE_MAINTAIN_SCROLL_AT_END_SMOOTH
: TIMELINE_MAINTAIN_SCROLL_AT_END;
// Legend animates every end pin of an animated list and queues a resize pin behind a running
// one, so a viewport resize (terminal drawer) would push the live end out of view for a beat.
// Runs from Legend's onLayout, inside the resize batch that flushes item growth after it, so
// the pin waits for that flush. scrollToEnd commits through a React update; flushSync paints it.
const listViewportHeightRef = useRef<number | null>(null);
const pinEndOnViewportResize = useStableCallback(
(event: { nativeEvent: { layout: { height: number } } }) => {
const { height } = event.nativeEvent.layout;
const previousHeight = listViewportHeightRef.current;
listViewportHeightRef.current = height;
if (previousHeight === null || previousHeight === height) return;
if (maintainScrollAtEnd !== TIMELINE_MAINTAIN_SCROLL_AT_END_SMOOTH) return;
const list = listRef.current;
if (!list) return;
const state = list.getState();
// Any scroll request clears Legend's follow while it runs, so the scroll-to-end settle
// reads as leaving the end. A reader who left the end band is still never pulled back.
if (
!state.isFollowingEnd &&
!resolveTimelineIsAtEnd({ ...state, scrollLength: previousHeight })
)
return;
queueMicrotask(() => flushSync(() => void list.scrollToEnd({ animated: false })));
},
);
const attachTimelineViewportElement = (viewportElement: HTMLDivElement | null) => {
setTimelineViewportElement(viewportElement);
if (!viewportElement) return;
Expand Down Expand Up @@ -1322,17 +1358,8 @@ const ConversationTimeline = memo(function ConversationTimeline({
onLoad={handleListLoad}
{...(anchoredEndSpace ? { anchoredEndSpace } : {})}
contentInsetEndAdjustment={anchoredEndSpace ? contentInsetEndAdjustment : 0}
maintainScrollAtEnd={
citationPositioning ||
(restoringThreadPosition && rememberedPosition?.atEnd === false) ||
anchoredEndSpace ||
!liveFollowEnabled ||
fullscreenAppRowId !== null
? false
: isWorking && !prefersReducedMotion && settlingListIdentity === null
? TIMELINE_MAINTAIN_SCROLL_AT_END_SMOOTH
: TIMELINE_MAINTAIN_SCROLL_AT_END
}
maintainScrollAtEnd={maintainScrollAtEnd}
onLayout={pinEndOnViewportResize}
maintainVisibleContentPosition={
findActive ||
citationPositioning ||
Expand Down
Loading