Skip to content

Commit 8fa5986

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 727d384 commit 8fa5986

4 files changed

Lines changed: 86 additions & 126 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
@@ -175,25 +175,30 @@ describe("MessagesTimeline messages", () => {
175175
});
176176

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

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

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

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ function AutomationMessageRow({ row }: { row: Extract<TimelineRow, { kind: "mess
165165
expanded && "w-full",
166166
)}
167167
>
168+
<MessageAuthorHeading>Automation</MessageAuthorHeading>
168169
<FoldedMessageHeader
169170
icon={CalendarClockIcon}
170171
label="Automation"
@@ -303,6 +304,7 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
303304
? { environmentId: ctx.activeThreadEnvironmentId, threadId: senderThreadId }
304305
: null,
305306
);
307+
const senderLabel = senderShell?.title.trim() || "Agent";
306308
const resolvedContext = resolveUserMessageContext(row.message);
307309
const previewImages = userImages.filter((image) => image.name.startsWith("preview-annotation-"));
308310
const revertTurnCount = row.revertTurnCount;
@@ -438,10 +440,12 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
438440
folded && expanded && "w-full",
439441
)}
440442
>
443+
{/* Outside the fold so a collapsed message still has a heading to navigate to. */}
444+
<MessageAuthorHeading>{folded ? senderLabel : "You"}</MessageAuthorHeading>
441445
{folded ? (
442446
<FoldedMessageHeader
443447
icon={MessagesSquareIcon}
444-
label={senderShell?.title.trim() || "Agent"}
448+
label={senderLabel}
445449
summary={foldSummary}
446450
expanded={expanded}
447451
onToggle={() => setExpanded((value) => !value)}
@@ -457,7 +461,6 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
457461
folded && !ctx.findActive && "max-h-96 overflow-auto",
458462
)}
459463
>
460-
<MessageAuthorHeading>You</MessageAuthorHeading>
461464
{(regularImages.length > 0 || userVideos.length > 0) && (
462465
<div className="mb-2 grid max-w-[210px] grid-cols-2 gap-2">
463466
{regularImages.map((image) => (

0 commit comments

Comments
 (0)