Skip to content

Commit fdd0de8

Browse files
author
Carl
committed
Merge main and wire local agent refresh in integration fixture
Signed-off-by: Carl <acda9e433d19dcd0e6b6840f7f4b98f3a56f1fab98049d444c087019e6d36560@buzz.block.builderlab.xyz>
2 parents 5f06da1 + fa3b720 commit fdd0de8

61 files changed

Lines changed: 2363 additions & 202 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docs/shell-design.md‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,20 @@ semantic tokens, UI authoring rules and the local component reference.
7272
tab. Each opening carries focus intent: topbar activation suppresses destination
7373
autofocus, while explicit New conversation, sidebar and deep-link openings keep
7474
their content focus. This intent is not saved in addresses or history; retry
75-
preserves it for the same opening. The selected page is a separately focusable,
75+
preserves it for the same opening. A focused Retry navigation control hands
76+
focus to main once retry removes it, even if reconnect temporarily remounts
77+
the shell. A new opening or focus elsewhere cancels this
78+
handoff. The selected page is a separately focusable,
7679
labelled tabpanel. Toolbar
7780
and overflow destinations remain native buttons using `aria-current` and
78-
focus main content on selection. Header pages never become companion launchers,
79-
and only the exact current page is selected.
81+
focus main content on selection. Header pages never become companion launchers.
82+
Independent header pages retain exact destination selection. Messages stays
83+
selected for registered sidebar/default-placement pages, including non-primary
84+
pages reached through search or links; their sidebar selection and route remain
85+
exact. Its tab labels the active child panel, and activating Messages from a
86+
child returns to the existing conversation view. More pages indicates this
87+
containing area with `aria-current="true"` (not `page`). Me and Settings remain
88+
separate; missing/unregistered destinations do not borrow Messages selection.
8089
The shell owns one joined Panel around navigation and page content, with a
8190
16px outer gutter (8px on narrow screens). Nested Panels keep their opaque
8291
fill and clipping but drop individual borders, radii, and shadows. Layout

‎src/app/App.tsx‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { AgentsContext } from "../features/agents/react";
77
import { ToastProvider } from "../shared/design-system/ui/Toast";
88
import { Button } from "../shared/design-system/ui/Button";
99
import { UpdateNotice } from "../features/updates/UpdateNotice";
10-
import { useEffect, useSyncExternalStore } from "react";
10+
import { useEffect, useRef, useSyncExternalStore } from "react";
1111
import { registerAppShortcuts } from "./shortcuts";
1212
import type { AppServices } from "./services";
1313
import { Settings } from "./Settings";
@@ -80,6 +80,20 @@ function ConnectedApp({ services }: { services: AppServices }) {
8080
);
8181
const restoring = client.status === "loading" || !!connection.restoring;
8282
const settings = route.target.kind === "settings";
83+
const retryFocus = useRef<string | undefined>(undefined);
84+
// A passive effect runs after the destination's own mount focus, so this
85+
// only fills in when focus would otherwise be left on the body.
86+
useEffect(() => {
87+
if (!retryFocus.current) return;
88+
if (retryFocus.current === route.state.attempt.id && !settings && restoring)
89+
return;
90+
if (
91+
retryFocus.current === route.state.attempt.id &&
92+
document.activeElement === document.body
93+
)
94+
document.getElementById("main-content")?.focus({ preventScroll: true });
95+
retryFocus.current = undefined;
96+
}, [restoring, settings, route.state.attempt]);
8397
const terminal =
8498
startup === "recovery" ||
8599
route.state.status === "failed" ||
@@ -254,7 +268,20 @@ function ConnectedApp({ services }: { services: AppServices }) {
254268
: "The destination is unavailable or isn’t supported yet. Your target has been kept for retry."}
255269
</p>
256270
{(!route.state.ingress || route.state.retryable) && (
257-
<Button type="button" onClick={route.retry}>
271+
<Button
272+
type="button"
273+
onClick={(event) => {
274+
const focused =
275+
event.currentTarget === document.activeElement;
276+
const before = services.navigation.snapshot().attempt.id;
277+
route.retry();
278+
// Retry can remove this control and briefly unmount the
279+
// shell; hand focus to main only once it has fallen away.
280+
const after = services.navigation.snapshot().attempt.id;
281+
retryFocus.current =
282+
focused && after !== before ? after : undefined;
283+
}}
284+
>
258285
Retry navigation
259286
</Button>
260287
)}

‎src/app/navigation.test.tsx‎

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -283,30 +283,40 @@ it("fails a completed ordinary-member read without exposing Membership", async (
283283
expect(screen.queryByRole("button", { name: "Membership" })).toBeNull();
284284
expect(screen.queryByRole("heading", { name: "Membership" })).toBeNull();
285285
});
286-
it("Retry navigation starts a fresh permission read after a failed roster", async () => {
287-
const fixture = membershipFixture();
288-
fixture.fail();
289-
const current = restoreMembership();
290-
await screen.findByRole("button", { name: "Retry navigation" });
291-
const before = fixture.rosterReads.length;
292-
expect(before).toBeGreaterThan(0);
293-
const release = fixture.hold();
294-
try {
295-
fireEvent.click(screen.getByRole("button", { name: "Retry navigation" }));
286+
it.each([true, false])(
287+
"Retry navigation refreshes permission and hands off only its own focus (focused: %s)",
288+
async (focused) => {
289+
const fixture = membershipFixture();
290+
fixture.fail();
291+
const current = restoreMembership();
292+
const retry = await screen.findByRole("button", {
293+
name: "Retry navigation",
294+
});
295+
const main = screen.getByRole("main");
296+
const elsewhere = screen.getByRole("link", { name: "Skip to content" });
297+
(focused ? retry : elsewhere).focus();
298+
const before = fixture.rosterReads.length;
299+
expect(before).toBeGreaterThan(0);
300+
const release = fixture.hold();
301+
try {
302+
fireEvent.click(retry);
303+
expect(focused ? main : elsewhere).toHaveFocus();
304+
await waitFor(() =>
305+
expect(fixture.rosterReads.length).toBeGreaterThan(before),
306+
);
307+
expectPending(current);
308+
expect(focused ? main : elsewhere).toHaveFocus();
309+
} finally {
310+
await act(async () => release());
311+
}
312+
expect(
313+
await screen.findByRole("heading", { name: "Membership" }),
314+
).toBeVisible();
296315
await waitFor(() =>
297-
expect(fixture.rosterReads.length).toBeGreaterThan(before),
316+
expect(current.navigation.snapshot().status).toBe("opened"),
298317
);
299-
expectPending(current);
300-
} finally {
301-
await act(async () => release());
302-
}
303-
expect(
304-
await screen.findByRole("heading", { name: "Membership" }),
305-
).toBeVisible();
306-
await waitFor(() =>
307-
expect(current.navigation.snapshot().status).toBe("opened"),
308-
);
309-
});
318+
},
319+
);
310320

311321
it("reconnects the selected Membership community after its transport fails", async () => {
312322
const fixture = membershipFixture();

‎src/app/services.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ export function createServices() {
8282
localActivity,
8383
);
8484
ctx.effect(() =>
85-
localAgents.bind({ snapshot: agents.local, subscribe: agents.subscribe }),
85+
localAgents.bind({
86+
snapshot: agents.local,
87+
subscribe: agents.subscribe,
88+
refresh: () => agents.refresh(),
89+
}),
8690
);
8791
const notifications = new NotificationsService(
8892
ctx,

‎src/app/shell/AppShell.test.tsx‎

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,3 +446,119 @@ it("uses chrome tabs with manual keyboard selection, page linkage, and isolated
446446
error.mockRestore();
447447
}
448448
});
449+
450+
it.each([false, true])(
451+
"keeps Messages selected for a child without losing exact navigation (compact: %s)",
452+
async (compact) => {
453+
vi.stubGlobal("matchMedia", (media: string) => ({
454+
media,
455+
matches: compact,
456+
addEventListener() {},
457+
removeEventListener() {},
458+
}));
459+
const current = createServices();
460+
services = current;
461+
const onSelect = vi.fn();
462+
const entries: RegisteredPage[] = [
463+
{ key: "buzz.me/me", title: "Me", placement: "topbar" },
464+
{ key: "buzz.channels/channels", title: "Channels", placement: "topbar" },
465+
{ key: "buzz.inbox/inbox", title: "Inbox", placement: "sidebar" },
466+
{ key: "example/top", title: "Top", placement: "topbar" },
467+
{ key: "example/tool", title: "Tool", placement: "toolbar" },
468+
].map((entry) => ({
469+
...entry,
470+
placement: entry.placement as "topbar" | "sidebar" | "toolbar",
471+
id: entry.key.slice(entry.key.indexOf("/") + 1),
472+
pluginId: entry.key.slice(0, entry.key.indexOf("/")),
473+
revision: "one",
474+
primary: true,
475+
component: () => null,
476+
}));
477+
const shell = (selected: string, pages = entries) => (
478+
<ToastProvider>
479+
<AppShell
480+
pages={pages}
481+
selected={selected}
482+
navigationAttempt=""
483+
onSelect={onSelect}
484+
tone="default"
485+
communities={current.communities}
486+
accountActions={current.accountActions}
487+
>
488+
<p>Child content</p>
489+
</AppShell>
490+
</ToastProvider>
491+
);
492+
const { rerender } = render(shell("buzz.inbox/inbox"));
493+
if (compact)
494+
await userEvent.click(
495+
screen.getByRole("button", { name: "Show navigation" }),
496+
);
497+
const inbox = within(
498+
screen.getByRole("navigation", { name: "Pages" }),
499+
).getByRole("button", { name: "Inbox" });
500+
expect(inbox).toHaveAttribute("aria-current", "page");
501+
if (compact)
502+
await userEvent.click(screen.getByRole("button", { name: "More pages" }));
503+
const nav = screen.getByRole("navigation", {
504+
name: compact ? "Header pages" : "Topbar pages",
505+
});
506+
const role = compact ? "button" : "tab";
507+
const messages = within(nav).getByRole(role, { name: "Messages" });
508+
if (compact) {
509+
expect(messages).toHaveAttribute("aria-current", "true");
510+
expect(screen.queryByRole("tabpanel")).not.toBeInTheDocument();
511+
await userEvent.click(messages);
512+
expect(onSelect).toHaveBeenCalledExactlyOnceWith(
513+
"buzz.channels/channels",
514+
);
515+
expect(document.getElementById("main-content")).toHaveFocus();
516+
return;
517+
}
518+
expect(messages).toHaveAttribute("aria-selected", "true");
519+
const panel = screen.getByRole("tabpanel", { name: "Messages" });
520+
expect(panel).toHaveAttribute("id", messages.getAttribute("aria-controls"));
521+
expect(panel).toHaveAttribute("aria-labelledby", messages.id);
522+
expect(panel).toHaveTextContent("Child content");
523+
await userEvent.click(messages);
524+
expect(onSelect).toHaveBeenCalledExactlyOnceWith("buzz.channels/channels", {
525+
focus: "preserve",
526+
});
527+
expect(messages).toHaveFocus();
528+
onSelect.mockClear();
529+
rerender(shell("buzz.channels/channels"));
530+
await userEvent.click(messages);
531+
expect(onSelect).not.toHaveBeenCalled();
532+
rerender(shell("example/top"));
533+
expect(within(nav).getByRole("tab", { name: "Top" })).toHaveAttribute(
534+
"aria-selected",
535+
"true",
536+
);
537+
rerender(shell("example/tool"));
538+
expect(
539+
within(nav).queryByRole("tab", { selected: true }),
540+
).not.toBeInTheDocument();
541+
expect(screen.getByRole("button", { name: "Tool" })).toHaveAttribute(
542+
"aria-current",
543+
"page",
544+
);
545+
rerender(shell("buzz.me/me"));
546+
expect(within(nav).getByRole("tab", { name: "Me" })).toHaveAttribute(
547+
"aria-selected",
548+
"true",
549+
);
550+
rerender(shell("settings"));
551+
expect(
552+
within(nav).queryByRole("tab", { selected: true }),
553+
).not.toBeInTheDocument();
554+
rerender(
555+
shell(
556+
"buzz.inbox/inbox",
557+
entries.filter((entry) => entry.key !== "buzz.inbox/inbox"),
558+
),
559+
);
560+
expect(
561+
within(nav).queryByRole("tab", { selected: true }),
562+
).not.toBeInTheDocument();
563+
},
564+
);

‎src/app/shell/AppShell.tsx‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import type { OpenTarget } from "../../features/navigation/targets";
1919
import { CommunityRail } from "../../features/communities/CommunityRail";
2020
import { ProfileButton } from "./ProfileButton";
2121
import { PageSearch, type SearchServices } from "./PageSearch";
22-
import { orderPages } from "./presentation";
22+
import { headerPageSelection, orderPages } from "./presentation";
2323
import { PageNavigation } from "./PageNavigation";
2424
import type { NavigationOpenOptions } from "../../features/navigation/controller";
2525
import {
@@ -157,7 +157,11 @@ export function AppShell({
157157
[pages],
158158
);
159159
const topbarPages = headerPages.filter((page) => page.placement === "topbar");
160-
const selectedTopbarPage = topbarPages.some((page) => page.key === selected);
160+
const selectedHeader = headerPageSelection(pages, selected);
161+
const selectedTopbarPage = topbarPages.some(
162+
(page) => page.key === selectedHeader,
163+
);
164+
const panelKey = selectedTopbarPage ? selectedHeader : selected;
161165
const toolbarPages = headerPages.filter(
162166
(page) => page.placement === "toolbar",
163167
);
@@ -292,7 +296,8 @@ export function AppShell({
292296
>
293297
<PageNavigation
294298
pages={topbarPages}
295-
selected={selected}
299+
selected={selectedHeader}
300+
currentPage={selected}
296301
onSelect={onSelect}
297302
placement="topbar"
298303
/>
@@ -357,7 +362,8 @@ export function AppShell({
357362
>
358363
<PageNavigation
359364
pages={headerPages}
360-
selected={selected}
365+
selected={selectedHeader}
366+
currentPage={selected}
361367
onSelect={(key) => {
362368
setOverflowOpen(false);
363369
onSelect(key);
@@ -430,11 +436,11 @@ export function AppShell({
430436
>
431437
<PanelFrame companion={companion}>
432438
<div
433-
id={`shell-page-${selected}`}
439+
id={`shell-page-${panelKey}`}
434440
{...(!compactPages && selectedTopbarPage
435441
? {
436442
role: "tabpanel",
437-
"aria-labelledby": `shell-page-${selected}-tab`,
443+
"aria-labelledby": `shell-page-${panelKey}-tab`,
438444
tabIndex: 0,
439445
"data-focus-inset": "",
440446
}

‎src/app/shell/PageNavigation.tsx‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ import { pagePresentation } from "./presentation";
1313
export function PageNavigation({
1414
pages,
1515
selected,
16+
currentPage = selected,
1617
onSelect,
1718
placement = "sidebar",
1819
}: {
1920
pages: readonly RegisteredPage[];
2021
selected: string;
22+
currentPage?: string;
2123
onSelect(key: string, options?: Pick<NavigationOpenOptions, "focus">): void;
2224
placement?: "sidebar" | "topbar" | "toolbar";
2325
}) {
@@ -28,6 +30,9 @@ export function PageNavigation({
2830
variant="chrome"
2931
value={pages.some((page) => page.key === selected) ? selected : null}
3032
onValueChange={(key) => onSelect(key, { focus: "preserve" })}
33+
onReselect={(key) => {
34+
if (key !== currentPage) onSelect(key, { focus: "preserve" });
35+
}}
3136
items={pages.map((page) => {
3237
const Badge = page.badge;
3338
return {
@@ -82,6 +87,9 @@ export function PageNavigation({
8287
key={page.key}
8388
onClick={select}
8489
selected={selected === page.key}
90+
aria-current={
91+
selected === page.key && currentPage !== selected ? true : undefined
92+
}
8593
label={label}
8694
title={label}
8795
variant="row"

0 commit comments

Comments
 (0)