Skip to content

The agent that grows with you

fix(desktop): trap focus in boot recovery

0xmosta758638c64cb4
diff --git a/apps/desktop/src/components/boot-failure-overlay.test.tsx b/apps/desktop/src/components/boot-failure-overlay.test.tsx
index dd55e83adb2..e9148c99e03 100644
--- a/apps/desktop/src/components/boot-failure-overlay.test.tsx
+++ b/apps/desktop/src/components/boot-failure-overlay.test.tsx
@@ -66,12 +66,32 @@ beforeEach(() => {
afterEach(cleanup)
describe('BootFailureOverlay', () => {
+ it('keeps keyboard focus inside the recovery surface', () => {
+ render(
+ <>
+ <button type="button">Background action</button>
+ <BootFailureOverlay />
+ </>
+ )
+
+ const recoverySurface = screen.getByRole('dialog', { name: /Hermes couldn't start/i })
+ const retry = screen.getByRole('button', { name: /retry/i })
+ const backgroundAction = screen.getByText(/background action/i)
+
+ retry.focus()
+ backgroundAction.focus()
+
+ expect(recoverySurface.getAttribute('aria-modal')).toBe('true')
+ expect(recoverySurface.contains(globalThis.document.activeElement)).toBe(true)
+ })
+
it('swaps to the in-place gateway settings view (no route nav) and back', async () => {
render(<BootFailureOverlay />)
fireEvent.click(screen.getByRole('button', { name: /gateway settings/i }))
// Recovery actions give way to the embedded panel (behind a Back control).
expect(await screen.findByRole('button', { name: /back/i })).toBeTruthy()
+ expect(screen.getByRole('dialog', { name: /gateway settings/i }).getAttribute('aria-modal')).toBe('true')
expect(screen.queryByRole('button', { name: /retry/i })).toBeNull()
fireEvent.click(screen.getByRole('button', { name: /back/i }))
diff --git a/apps/desktop/src/components/boot-failure-overlay.tsx b/apps/desktop/src/components/boot-failure-overlay.tsx
index e6a432df697..7f9fa3d4104 100644
--- a/apps/desktop/src/components/boot-failure-overlay.tsx
+++ b/apps/desktop/src/components/boot-failure-overlay.tsx
@@ -1,7 +1,9 @@
import { useStore } from '@nanostores/react'
+import { Dialog as DialogPrimitive } from 'radix-ui'
import { type ComponentProps, lazy, type ReactNode, Suspense, useEffect, useState } from 'react'
import { Button } from '@/components/ui/button'
+import { DialogPortalContainerContext } from '@/components/ui/dialog-portal-context'
import { ErrorIcon } from '@/components/ui/error-state'
import { Loader } from '@/components/ui/loader'
import { LogView } from '@/components/ui/log-view'
@@ -44,6 +46,30 @@ type RecoveryView = 'connect' | 'recovery'
// exited during startup, bootstrap latched, …). Without this the app shell
// renders dead — "gateway offline", no composer, only a toast — with no way
// to retry, repair the install, switch the gateway, or find the logs.
+function BootFailureModal({ children, title }: { children: ReactNode; title?: string }) {
+ const [contentNode, setContentNode] = useState<HTMLDivElement | null>(null)
+
+ return (
+ <DialogPrimitive.Root open>
+ <DialogPrimitive.Portal>
+ <DialogPrimitive.Content aria-describedby={undefined} aria-modal="true" asChild ref={setContentNode}>
+ <div
+ className="fixed inset-0 z-(--z-setup) flex items-center justify-center bg-(--ui-chat-surface-background) p-6"
+ // Masks the whole app on boot failure — must stay filled under window
+ // glass. Contract: `[data-glass-opaque]` in styles.css.
+ data-glass-opaque=""
+ >
+ <DialogPortalContainerContext.Provider value={contentNode}>
+ {title ? <DialogPrimitive.Title className="sr-only">{title}</DialogPrimitive.Title> : null}
+ {children}
+ </DialogPortalContainerContext.Provider>
+ </div>
+ </DialogPrimitive.Content>
+ </DialogPrimitive.Portal>
+ </DialogPrimitive.Root>
+ )
+}
+
export function BootFailureOverlay() {
const boot = useStore($desktopBoot)
const onboarding = useStore($desktopOnboarding)
@@ -350,12 +376,7 @@ export function BootFailureOverlay() {
if (view === 'connect') {
return (
- <div
- className="fixed inset-0 z-(--z-setup) flex items-center justify-center bg-(--ui-chat-surface-background) p-6"
- // Masks the whole app on boot failure — must stay filled under window
- // glass. Contract: `[data-glass-opaque]` in styles.css.
- data-glass-opaque=""
- >
+ <BootFailureModal title={copy.gatewaySettings}>
<div className="flex max-h-[86vh] w-full max-w-[46rem] flex-col overflow-hidden rounded-xl border border-(--stroke-nous) bg-(--ui-chat-bubble-background) shadow-nous">
{/* Subtle back affordance (projects/overlay idiom): muted → foreground
on hover, no divider. */}
@@ -373,24 +394,21 @@ export function BootFailureOverlay() {
</Suspense>
</div>
</div>
- </div>
+ </BootFailureModal>
)
}
return (
- <div
- className="fixed inset-0 z-(--z-setup) flex items-center justify-center bg-(--ui-chat-surface-background) p-6"
- // Masks the whole app on boot failure — must stay filled under window
- // glass. Contract: `[data-glass-opaque]` in styles.css.
- data-glass-opaque=""
- >
+ <BootFailureModal>
<div className="w-full max-w-[40rem] overflow-hidden rounded-xl border border-(--stroke-nous) bg-(--ui-chat-bubble-background) shadow-nous">
<div className="flex items-start gap-3 px-5 py-4">
<ErrorIcon className="mt-0.5" size="1.25rem" />
<div>
- <h2 className="text-[0.9375rem] font-semibold tracking-tight">
- {remoteReauth ? copy.remoteTitle : cloudDown ? copy.cloudDownTitle : copy.title}
- </h2>
+ <DialogPrimitive.Title asChild>
+ <h2 className="text-[0.9375rem] font-semibold tracking-tight">
+ {remoteReauth ? copy.remoteTitle : cloudDown ? copy.cloudDownTitle : copy.title}
+ </h2>
+ </DialogPrimitive.Title>
<p className="mt-1 text-[0.8125rem] leading-5 text-(--ui-text-tertiary)">
{remoteReauth ? copy.remoteDescription : cloudDown ? copy.cloudDownDescription : copy.description}
</p>
@@ -445,6 +463,6 @@ export function BootFailureOverlay() {
) : null}
</div>
</div>
- </div>
+ </BootFailureModal>
)
}