Skip to content

Commit 60f68e8

Browse files
fix(clients): expanding a heading at the live end keeps following a streaming turn
Fold toggles called cancelScroll() and then anchorVisibleContent(). On Legend List 3.7.2 an anchor ends end-follow until the reader scrolls, and cancelling first skipped the list's own check that leaves the live end alone, so a turn streaming below stopped following. While a turn runs and the list follows the end, a toggle now leaves following in charge; other toggles still hold the heading in place. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent fc7da9d commit 60f68e8

3 files changed

Lines changed: 45 additions & 5 deletions

File tree

‎apps/mobile/src/features/threads/ThreadFeed.tsx‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3360,9 +3360,11 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
33603360

33613361
const preserveDisclosurePosition = (anchorKey: string | null) => {
33623362
const list = listRef.current;
3363-
if (anchorKey !== null) {
3364-
list?.cancelScroll();
3365-
list?.anchorVisibleContent({ key: anchorKey });
3363+
const working = props.activeWorkStartedAt !== null || props.runlessWorkActive === true;
3364+
// An anchor ends end-follow until the reader scrolls, so a streaming turn keeps the live end.
3365+
if (anchorKey !== null && list && !(working && list.getState().isFollowingEnd)) {
3366+
list.cancelScroll();
3367+
list.anchorVisibleContent({ key: anchorKey });
33663368
}
33673369
if (list && anchorKey && !reduceMotion) {
33683370
const state = list.getState();

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,41 @@ describe("MessagesTimeline work rows", () => {
262262
});
263263
});
264264

265+
it("keeps following a streaming turn after a heading is expanded at the bottom", async () => {
266+
const props = { ...baseProps(), isWorking: true };
267+
const runId = RunId.make("live-run");
268+
const container = document.createElement("div");
269+
container.style.cssText =
270+
"height: min(600px, 100vh); width: 900px; display: flex; flex-direction: column;";
271+
const entries = [
272+
...Array.from({ length: 12 }, (_, index) =>
273+
message(`Earlier context ${index}`, {}, `context-${index}`),
274+
),
275+
message("Progress details\n\n".repeat(50), { role: "assistant", runId }, "progress"),
276+
message("Done", { role: "assistant", runId }, "final"),
277+
];
278+
await using screen = await render(<MessagesTimeline {...props} timelineEntries={entries} />, {
279+
container,
280+
});
281+
const heading = screen.getByRole("button", { name: /^Worked for/ });
282+
await expect.element(heading).toHaveStyle({ pointerEvents: "auto" });
283+
const viewport = props.listRef.current!.getScrollableNode()!;
284+
const distanceFromEnd = () =>
285+
viewport.scrollHeight - viewport.clientHeight - viewport.scrollTop;
286+
await vi.waitFor(() => expect(distanceFromEnd()).toBeLessThan(2));
287+
await heading.click();
288+
await screen.rerender(
289+
<MessagesTimeline
290+
{...props}
291+
timelineEntries={[
292+
...entries,
293+
message("Streamed reply\n\n".repeat(40), { role: "assistant", runId }, "streamed"),
294+
]}
295+
/>,
296+
);
297+
await vi.waitFor(() => expect(distanceFromEnd()).toBeLessThan(2));
298+
});
299+
265300
it.each(["delegated", "legacy", "missing"] as const)(
266301
"uses the reported task for %s completion notifications",
267302
async (source) => {

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,11 @@ const ConversationTimeline = memo(function ConversationTimeline({
469469
const findActive = findExpanded;
470470

471471
const preserveDisclosurePosition = (anchorKey: string) => {
472-
listRef.current?.cancelScroll();
473-
listRef.current?.anchorVisibleContent({ key: anchorKey });
472+
const list = listRef.current;
473+
// An anchor ends end-follow until the reader scrolls, so a streaming turn keeps the live end.
474+
if (!list || (isWorking && list.getState().isFollowingEnd)) return;
475+
list.cancelScroll();
476+
list.anchorVisibleContent({ key: anchorKey });
474477
};
475478

476479
const onToggleTurnFold = (runId: RunId) => {

0 commit comments

Comments
 (0)