Give chat a real scroll contract: open at latest, stick, jump back

The conversation pane had no scroll management at all - it opened at
the top of history, ignored arriving messages, and offered no way back
down other than dragging through long replies.

- Opening a conversation lands on the newest message (the component is
  keyed by space, so mount = open)
- A reader at the bottom stays pinned as new messages arrive; a reader
  up in history is left undisturbed
- The moment the reader leaves the bottom, a floating "Jump to latest"
  pill appears above the composer; clicking it smooth-scrolls back and
  the pill hides itself again
- The scroll region is a proper role="log" landmark; e2e seeds a dozen
  multi-line messages over real IPC, scrolls to the top, and drives the
  pill's appear -> click -> return-to-bottom -> disappear cycle
This commit is contained in:
ZacharyZhang-NY committed 2026-07-08 23:55:52 -04:00
1 parent 9834714fa6
commit 78e88807da
4 files changed
+129 -19

No files matched your search

+38
View File
@@ -181,6 +181,44 @@ test("onboards, hires, and creates work in the Electron shell", async () => {
await page.getByRole("button", { name: "Send" }).click();
await expect(page.getByText("Alex Turing").first()).toBeVisible();
// Scrolling up into history surfaces a jump-back pill above the composer.
await page.evaluate(async () => {
const api = (window as unknown as { agentCompany: {
loadSnapshot: () => Promise<{ ok: true; data: {
activeOrgId: string;
employees: Array<{ id: string; orgId: string }>;
chatSpaces: Array<{ id: string; orgId: string; name: string }>;
} }>;
sendMessage: (input: unknown) => Promise<unknown>;
} }).agentCompany;
const snapshot = await api.loadSnapshot();
const orgId = snapshot.data.activeOrgId;
const employee = snapshot.data.employees.find((item) => item.orgId === orgId)!;
const general = snapshot.data.chatSpaces.find((item) => item.orgId === orgId && item.name === "general")!;
for (let index = 0; index < 12; index++) {
await api.sendMessage({
orgId,
spaceId: general.id,
threadId: null,
senderType: "employee",
senderId: employee.id,
bodyMd: `Scroll filler ${index}\n\nline\n\nline\n\nline`,
attachmentFileIds: [],
});
}
});
const chatLog = page.getByRole("log", { name: "Conversation messages" });
await expect(page.getByText("Scroll filler 11").first()).toBeVisible();
// Pinned to the bottom: no pill.
await expect(page.getByRole("button", { name: "Jump to latest" })).toHaveCount(0);
await chatLog.evaluate((el) => { el.scrollTop = 0; });
const jumpButton = page.getByRole("button", { name: "Jump to latest" });
await expect(jumpButton).toBeVisible();
await jumpButton.click();
await expect(jumpButton).not.toBeVisible();
const nearBottom = await chatLog.evaluate((el) => el.scrollHeight - el.scrollTop - el.clientHeight < 60);
expect(nearBottom).toBe(true);
await verifyPagesDoNotOverflow(page);
} finally {
await app.close();