Skip to content

Commit 6de1c08

Browse files
committed
Keep startup notices outside the focus tree
Signed-off-by: Codex AI Agent <[email protected]>
1 parent ee16958 commit 6de1c08

7 files changed

Lines changed: 52 additions & 5 deletions

File tree

‎index.html‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
</picture>
2020
</div>
2121
<div id="root" inert aria-hidden="true"></div>
22+
<div id="buzz-toast-root" inert aria-hidden="true"></div>
2223
<script src="/launch-init.js"></script>
2324
<script type="module" src="/src/main.tsx"></script>
2425
</body>

‎src/app/launch.test.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ beforeEach(() => {
1212
return 0;
1313
});
1414
document.body.innerHTML =
15-
'<div id="buzz-launch"><img src="/buzz-loading-mark.svg"></div><div id="root" inert aria-hidden="true"></div>';
15+
'<div id="buzz-launch"><img src="/buzz-loading-mark.svg"></div><div id="root" inert aria-hidden="true"></div><div id="buzz-toast-root" inert aria-hidden="true"></div>';
1616
const element = document.getElementById("buzz-launch");
1717
if (!element) throw new Error("Missing launch fixture");
1818
launch = element;
@@ -45,6 +45,12 @@ it("finishes the first cycle before fading when content is ready early", async (
4545
expect(launch.isConnected).toBe(false);
4646
expect(document.getElementById("root")).not.toHaveAttribute("inert");
4747
expect(document.getElementById("root")).not.toHaveAttribute("aria-hidden");
48+
expect(document.getElementById("buzz-toast-root")).not.toHaveAttribute(
49+
"inert",
50+
);
51+
expect(document.getElementById("buzz-toast-root")).not.toHaveAttribute(
52+
"aria-hidden",
53+
);
4854
});
4955

5056
it("keeps looping while content is pending, then finishes the current cycle", async () => {

‎src/app/launch.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ let revision = 0;
1616
const fallbackStartedAt = performance.now();
1717

1818
function revealRoot() {
19-
const root = document.getElementById("root");
20-
root?.removeAttribute("inert");
21-
root?.removeAttribute("aria-hidden");
19+
for (const id of ["root", "buzz-toast-root"]) {
20+
const root = document.getElementById(id);
21+
root?.removeAttribute("inert");
22+
root?.removeAttribute("aria-hidden");
23+
}
2224
}
2325

2426
function startedAt() {

‎src/shared/design-system/ui/Toast.test.tsx‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,30 @@ afterEach(() => {
1919
vi.restoreAllMocks();
2020
});
2121

22+
it("keeps startup notices inside the inert toast host", () => {
23+
const host = document.createElement("div");
24+
host.id = "buzz-toast-root";
25+
host.setAttribute("inert", "");
26+
host.setAttribute("aria-hidden", "true");
27+
document.body.append(host);
28+
try {
29+
render(
30+
<ToastProvider>
31+
<ToastNotice title="Ready to update" onDismiss={() => {}}>
32+
<Button>Update now</Button>
33+
</ToastNotice>
34+
</ToastProvider>,
35+
);
36+
expect(host).toContainElement(
37+
screen.getByRole("button", { name: "Update now", hidden: true }),
38+
);
39+
expect(screen.queryByRole("button", { name: "Update now" })).toBeNull();
40+
} finally {
41+
cleanup();
42+
host.remove();
43+
}
44+
});
45+
2246
it("StrictMode and rerenders keep one notice and the latest action; cleanup is not dismissal", async () => {
2347
const oldRetry = vi.fn();
2448
const retry = vi.fn();

‎src/shared/design-system/ui/Toast.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ export function ToastProvider({ children }: { children: ReactNode }) {
2222
function ToastViewport() {
2323
const { toasts } = BaseToast.useToastManager<NoticeData>();
2424
return (
25-
<BaseToast.Portal>
25+
<BaseToast.Portal
26+
container={document.getElementById("buzz-toast-root") ?? undefined}
27+
>
2628
<BaseToast.Viewport
2729
data-buzz-ui=""
2830
className="buzz-toast-viewport"

‎tests/browser/fixture.mjs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,6 +1692,9 @@ export const test = base.extend({
16921692
const root = document.getElementById("root");
16931693
root?.removeAttribute("inert");
16941694
root?.removeAttribute("aria-hidden");
1695+
const toastRoot = document.getElementById("buzz-toast-root");
1696+
toastRoot?.removeAttribute("inert");
1697+
toastRoot?.removeAttribute("aria-hidden");
16951698
observer.disconnect();
16961699
});
16971700
observer.observe(document, { childList: true, subtree: true });

‎tests/browser/startup.spec.mjs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,11 @@ test("launch waits for the initial sidebar and message history before revealing
387387
await expect(launch).toBeVisible();
388388
await expect(page.locator("#root")).toHaveAttribute("inert", "");
389389
await expect(page.locator("#root")).toHaveAttribute("aria-hidden", "true");
390+
await expect(page.locator("#buzz-toast-root")).toHaveAttribute("inert", "");
391+
await expect(page.locator("#buzz-toast-root")).toHaveAttribute(
392+
"aria-hidden",
393+
"true",
394+
);
390395
await expect(
391396
page.locator('[aria-label="Channel sidebar"][data-buzz-launch-pending]'),
392397
).toBeAttached();
@@ -410,6 +415,10 @@ test("launch waits for the initial sidebar and message history before revealing
410415
await expect(launch).toHaveCount(0);
411416
await expect(page.locator("#root")).not.toHaveAttribute("inert");
412417
await expect(page.locator("#root")).not.toHaveAttribute("aria-hidden");
418+
await expect(page.locator("#buzz-toast-root")).not.toHaveAttribute("inert");
419+
await expect(page.locator("#buzz-toast-root")).not.toHaveAttribute(
420+
"aria-hidden",
421+
);
413422
} finally {
414423
app.relay.releaseUnread();
415424
head.release();

0 commit comments

Comments
 (0)