Skip to content

Commit 67885e8

Browse files
PR Batch Testerclaude
andcommitted
fix(web): folded messages keep their heading, and the list patch stays web-only
Automation prompts and messages from other agents only had a heading inside their collapsed body, so a thread that starts with an automation prompt still had no first heading to wrap to. Their heading now sits outside the fold. The test now waits for the list to reach the end and checks the first and last headings are first and last in DOM order, with folded messages at both ends. The LegendList position change now only patches the react builds the web app uses, so mobile's list is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent a6bb873 commit 67885e8

4 files changed

Lines changed: 92 additions & 128 deletions

File tree

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

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -177,25 +177,30 @@ describe("MessagesTimeline messages", () => {
177177
});
178178

179179
it("keeps the first and last message headings reachable from either end", async () => {
180+
setup();
180181
const props = baseProps();
182+
// Folded messages at both ends: their headings must not live inside the fold.
181183
const entries = Array.from({ length: 120 }, (_, index) =>
182-
message(
183-
index === 0
184-
? "First turn"
185-
: index === 119
186-
? "Last turn"
187-
: `Turn ${index}:\n\n${"x ".repeat(200)}`,
188-
{ role: index % 2 === 0 ? "user" : "assistant" },
189-
`turn-${index}`,
190-
),
184+
index === 0
185+
? message("First turn", { scheduledTaskId: TASK_ID }, "turn-0")
186+
: index === 119
187+
? message(
188+
"Last turn",
189+
{ createdBy: "agent", senderThreadId: ThreadId.make("thread-sender") },
190+
"turn-119",
191+
)
192+
: message(
193+
`Turn ${index}:\n\n${"x ".repeat(200)}`,
194+
{ role: index % 2 === 0 ? "user" : "assistant" },
195+
`turn-${index}`,
196+
),
191197
);
192198
await using screen = await renderElement(
193199
<MessagesTimeline {...props} timelineEntries={entries} />,
194200
);
201+
const headings = () => [...screen.container.querySelectorAll("h3")];
195202
const headingFor = (text: string) =>
196-
[...screen.container.querySelectorAll("h3")].find((heading) =>
197-
heading.parentElement?.textContent?.includes(text),
198-
);
203+
headings().find((heading) => heading.parentElement?.textContent?.includes(text));
199204
const viewport = props.listRef.current!.getScrollableNode()!;
200205
// A screen reader scrolls the heading it moves to into view.
201206
const expectHeadingInView = async (text: string, neighbour: string) => {
@@ -207,9 +212,13 @@ describe("MessagesTimeline messages", () => {
207212
expect(row.bottom).toBeGreaterThan(view.top);
208213
};
209214

210-
await vi.waitFor(() => expect(headingFor("Last turn")).toBeDefined());
211-
expect(headingFor("First turn")).toBeDefined();
215+
await vi.waitFor(() => expect(screen.text()).toContain("Turn 118:"));
212216
expect(screen.text()).not.toContain("Turn 60:");
217+
// Wrapping follows DOM order, so the ends must also sit first and last.
218+
await vi.waitFor(() => {
219+
expect(headings()[0]).toBe(headingFor("First turn"));
220+
expect(headings().at(-1)).toBe(headingFor("Last turn"));
221+
});
213222

214223
await expectHeadingInView("First turn", "Turn 1:");
215224
expect(headingFor("Last turn")).toBeDefined();

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ function AutomationMessageRow({ row }: { row: Extract<TimelineRow, { kind: "mess
166166
expanded && "w-full",
167167
)}
168168
>
169+
<MessageAuthorHeading>Automation</MessageAuthorHeading>
169170
<FoldedMessageHeader
170171
icon={CalendarClockIcon}
171172
label="Automation"
@@ -304,6 +305,7 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
304305
? { environmentId: ctx.activeThreadEnvironmentId, threadId: senderThreadId }
305306
: null,
306307
);
308+
const senderLabel = senderShell?.title.trim() || "Agent";
307309
const resolvedContext = resolveUserMessageContext(
308310
userMessage.attribution === "guest" ? { ...row.message, text: userMessage.text } : row.message,
309311
);
@@ -448,10 +450,18 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
448450
folded && expanded && "w-full",
449451
)}
450452
>
453+
{/* Outside the fold so a collapsed message still has a heading to navigate to. */}
454+
<MessageAuthorHeading>
455+
{folded
456+
? senderLabel
457+
: userMessage.guestName === undefined
458+
? "You"
459+
: `${userMessage.guestName} (guest)`}
460+
</MessageAuthorHeading>
451461
{folded ? (
452462
<FoldedMessageHeader
453463
icon={MessagesSquareIcon}
454-
label={senderShell?.title.trim() || "Agent"}
464+
label={senderLabel}
455465
summary={foldSummary}
456466
expanded={expanded}
457467
onToggle={() => setExpanded((value) => !value)}
@@ -467,9 +477,6 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
467477
folded && !ctx.findActive && "max-h-96 overflow-auto",
468478
)}
469479
>
470-
<MessageAuthorHeading>
471-
{userMessage.guestName === undefined ? "You" : `${userMessage.guestName} (guest)`}
472-
</MessageAuthorHeading>
473480
{(regularImages.length > 0 || userVideos.length > 0) && (
474481
<div className="mb-2 grid max-w-[210px] grid-cols-2 gap-2">
475482
{regularImages.map((image) => (

0 commit comments

Comments
 (0)