Skip to content

Commit ca697c8

Browse files
committed
fix(web): finish grouped reveals after outer layout grows
1 parent ec0d739 commit ca697c8

2 files changed

Lines changed: 37 additions & 15 deletions

File tree

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

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -526,12 +526,19 @@ describe("MessagesTimeline messages", () => {
526526
expect((globalThis as { __t3Xss?: number }).__t3Xss).toBeUndefined();
527527
});
528528

529-
it.each(["inline", "delayed", "grouped-delayed"])("reveals %s output", async (mode) => {
529+
const revealModes = ["inline", "delayed", "grouped-delayed", "grouped-end"];
530+
it.each(revealModes)("reveals %s output", async (mode) => {
530531
setup();
531-
environmentQuery.data = null;
532+
environmentQuery.data =
533+
mode === "grouped-end"
534+
? {
535+
output: { text: `${"output line\n".repeat(10)}TOOL_INPUT_END`, truncated: false },
536+
running: false,
537+
}
538+
: null;
532539
environmentQuery.error = null;
533540
const props = baseProps();
534-
const composerOverlayHeight = 200;
541+
const composerOverlayHeight = mode === "grouped-end" ? 140 : 200;
535542
const tallEntries = Array.from({ length: 12 }, (_, index) =>
536543
message(
537544
`Message ${index}\n\n${"Long paragraph. ".repeat(80)}`,
@@ -580,7 +587,7 @@ describe("MessagesTimeline messages", () => {
580587
}),
581588
},
582589
},
583-
...(mode === "grouped-delayed"
590+
...(mode.startsWith("grouped-")
584591
? [
585592
{
586593
id: "another-tool",
@@ -598,14 +605,17 @@ describe("MessagesTimeline messages", () => {
598605
},
599606
]
600607
: []),
601-
...tallEntries.slice(6),
608+
...(mode === "grouped-end"
609+
? [message("Completed.", { role: "assistant" }, "final-message")]
610+
: tallEntries.slice(6)),
602611
]}
603612
/>
604613
);
605614
await using screen = await renderElement(timeline());
615+
if (mode === "grouped-end") screen.container.style.height = "648px";
606616
await vi.waitFor(() => expect(props.listRef.current?.getScrollableNode()).toBeTruthy());
607617
const viewport = props.listRef.current!.getScrollableNode()!;
608-
if (mode === "grouped-delayed") {
618+
if (mode.startsWith("grouped-")) {
609619
await act(() => {
610620
void props.listRef.current!.scrollToIndex({ index: 6, animated: false });
611621
});
@@ -624,13 +634,19 @@ describe("MessagesTimeline messages", () => {
624634
screen.container.querySelector('[data-work-entry-id="tool-near-composer"]'),
625635
).not.toBeNull(),
626636
);
627-
await click(
628-
screen.container.querySelector<HTMLElement>('[data-work-entry-id="tool-near-composer"]')!,
629-
);
630-
await vi.waitFor(() => expect(screen.text()).toContain("Loading output"));
631-
await click(group());
637+
if (mode === "grouped-delayed") {
638+
await click(
639+
screen.container.querySelector<HTMLElement>('[data-work-entry-id="tool-near-composer"]')!,
640+
);
641+
await vi.waitFor(() => expect(screen.text()).toContain("Loading output"));
642+
await click(group());
643+
}
632644
}
633645
const header = () => {
646+
if (mode === "grouped-end")
647+
return screen.container.querySelector<HTMLElement>(
648+
'[data-work-entry-id="tool-near-composer"]',
649+
)!;
634650
if (mode === "grouped-delayed")
635651
return screen.container.querySelector<HTMLElement>(
636652
'[data-timeline-row-kind="work-toggle"] button',
@@ -661,7 +677,7 @@ describe("MessagesTimeline messages", () => {
661677
if (mode === "grouped-delayed") {
662678
await vi.waitFor(() => expect(viewport.scrollTop).toBeGreaterThan(collapsedScrollTop));
663679
}
664-
if (mode !== "inline") {
680+
if (mode !== "inline" && mode !== "grouped-end") {
665681
await vi.waitFor(() =>
666682
expect(header().getBoundingClientRect().bottom).toBeLessThanOrEqual(visibleBottom() + 1),
667683
);
@@ -679,8 +695,10 @@ describe("MessagesTimeline messages", () => {
679695
await vi.waitFor(() =>
680696
expect(inputEnd().getBoundingClientRect().bottom).toBeLessThanOrEqual(visibleBottom() + 1),
681697
);
682-
expect(header().getBoundingClientRect().top).toBeGreaterThanOrEqual(
683-
viewport.getBoundingClientRect().top,
698+
await vi.waitFor(() =>
699+
expect(header().getBoundingClientRect().top).toBeGreaterThanOrEqual(
700+
viewport.getBoundingClientRect().top,
701+
),
684702
);
685703
});
686704
});

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,6 @@ const ConversationTimeline = memo(function ConversationTimeline({
490490
const revealExpandedDisclosure = () => {
491491
const pending = disclosureRevealRef.current;
492492
if (!pending || pending.identity !== listIdentityKey) return;
493-
if (pending.ready) disclosureRevealRef.current = null;
494493
const anchorKey = pending.key;
495494
const state = listRef.current?.getState();
496495
const element = listRef.current?.getScrollableNode();
@@ -512,6 +511,10 @@ const ConversationTimeline = memo(function ConversationTimeline({
512511
composerOverlayHeight: contentInsetEndAdjustment,
513512
anchorOffset: CHAT_TIMELINE_ANCHOR_OFFSET,
514513
});
514+
// Nested lists can finish measuring before their height reaches the outer scroller.
515+
if (pending.ready && element.scrollTop + delta <= element.scrollHeight - element.clientHeight) {
516+
disclosureRevealRef.current = null;
517+
}
515518
if (delta > 0) {
516519
element.scrollBy({ top: delta, behavior: prefersReducedMotion ? "auto" : "smooth" });
517520
}
@@ -1226,6 +1229,7 @@ const ConversationTimeline = memo(function ConversationTimeline({
12261229
contentSizeFrame = requestAnimationFrame(() => {
12271230
contentSizeFrame = null;
12281231
handleContentSizeChanged(laidOutData);
1232+
if (disclosureRevealRef.current?.ready) scheduleDisclosureSettle();
12291233
});
12301234
};
12311235
const stopListeningToContentSize = list

0 commit comments

Comments
 (0)