Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop-app): keep the not-ready chat drawer inert and defer switcher focus
Diego Zacariasb40a81109d10
diff --git a/desktop-app/ui/src/App.tsx b/desktop-app/ui/src/App.tsxindex b27d0b818..1bd3d8f4b 100644--- a/desktop-app/ui/src/App.tsx+++ b/desktop-app/ui/src/App.tsx@@ -797,14 +797,18 @@ export function App() {setChatDrawerReady(false)}, [activeSandboxUiApp?.appRef, chatDrawerVisible])- // Once the drawer becomes visible after a `chat.switcher` on a closed drawer,- // the switcher is mounted — bump its focus request so it opens the dropdown.+ // Once the drawer becomes visible AND ready after a `chat.switcher` on a closed+ // drawer, the switcher is mounted and no longer `inert` — bump its focus request+ // so it opens the dropdown and moves focus onto it. Gating on `chatDrawerReady`+ // (not just visibility) is required: the drawer subtree is `inert` from mount+ // until the embed acks its shrunk bounds, and a `focus()` fired while inert is a+ // silent no-op, so bumping on visibility alone would open the switcher unfocused.React.useEffect(() => {- if (chatDrawerVisible && pendingChatSwitcherFocusRef.current) {+ if (chatDrawerVisible && chatDrawerReady && pendingChatSwitcherFocusRef.current) {pendingChatSwitcherFocusRef.current = falsesetChatSwitcherFocusRequestId(value => value + 1)}- }, [chatDrawerVisible])+ }, [chatDrawerVisible, chatDrawerReady])const handleSandboxUiBoundsApplied = React.useCallback(() => {if (appNotificationDrawerOpen) setNotificationDrawerReady(true)diff --git a/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx b/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsxindex 254c1bb61..8f0e6f26c 100644--- a/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx+++ b/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx@@ -20,6 +20,7 @@ const sandboxUiPageHarness = vi.hoisted(() => ({chatDrawerOpen?: booleanonToggleChatDrawer?: () => voidonEmbeddedAppMounted?: () => void+ onEmbedBoundsApplied?: () => voidonEmbedSlotTopChange?: (topPx: number) => void},}))@@ -266,6 +267,71 @@ describe('App chat drawer — reopen preserves the last-viewed chat', () => {expect(screen.getByRole('button', { name: 'Open chats' }).textContent).toContain('Second chat')})+ // The drawer's not-ready subtree is `inert`, and a `focus()` fired inside an+ // inert subtree is a silent no-op. So the `chat.switcher` shortcut (which opens+ // the drawer, then opens+focuses the switcher) must defer the open until the+ // embed acks its bounds and the drawer is READY — bumping on visibility alone+ // would open the option list while still inert, leaving it unfocused. This pins+ // that ordering at the observable level: options appear only after ready.+ it('defers the chat.switcher open until the drawer is ready, not merely visible', () => {+ currentController = makeController({+ selectedAgent: 'alpha',+ activeChatId: 'chat-1',+ navItem: DESKTOP_ROUTES.chat,+ chatList: CHAT_LIST,+ } as Partial<AppController>)+ let commandCb: ((commandId: string, source: string) => void) | null = null+ Object.defineProperty(window, 'clerum', {+ configurable: true,+ value: {+ shortcuts: {+ onCommand: vi.fn((cb: (commandId: string, source: string) => void) => {+ commandCb = cb+ return vi.fn()+ }),+ },+ app: { rendererReady: vi.fn().mockResolvedValue(undefined) },+ sandboxUi: {+ listApps: vi.fn().mockResolvedValue({ apps: [] }),+ listPendingDeepLinks: vi.fn().mockResolvedValue({ links: [] }),+ clearPendingDeepLinks: vi.fn().mockResolvedValue(undefined),+ onDeepLink: vi.fn(() => vi.fn()),+ setVisible: vi.fn().mockResolvedValue(undefined),+ setBounds: vi.fn().mockResolvedValue(undefined),+ focusActive: vi.fn().mockResolvedValue(true),+ close: vi.fn().mockResolvedValue(undefined),+ },+ } as unknown as Window['clerum'],+ })++ render(<App />)++ // Launch the app and mark the embed mounted so `chat.switcher` (eligibility+ // `app-mounted`) is dispatchable, then manually close the drawer so the+ // shortcut takes the "open the drawer first, defer focus" branch.+ act(() => {+ sidebarHarness.props?.onOpenSandboxUiApp?.({+ appRef: 'ns/app',+ label: 'App',+ defaultPath: '/',+ })+ })+ act(() => sandboxUiPageHarness.props?.onEmbeddedAppMounted?.())+ act(() => sandboxUiPageHarness.props?.onToggleChatDrawer?.())+ expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(false)++ // Fire the shortcut: the drawer reopens but has NOT acked its bounds, so its+ // subtree is inert. The switcher must stay CLOSED — no options rendered yet.+ act(() => commandCb?.('chat.switcher', 'shortcut-host'))+ expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(true)+ expect(screen.queryByRole('option')).toBeNull()++ // Embed acks its bounds → drawer becomes ready (inert lifted) → the deferred+ // request fires and the switcher opens, now focusable.+ act(() => sandboxUiPageHarness.props?.onEmbedBoundsApplied?.())+ expect(screen.queryAllByRole('option').length).toBeGreaterThan(0)+ })+it('reverts the notification tray to overlay form while the chat drawer is visible', () => {currentController = makeController({selectedAgent: 'alpha',diff --git a/desktop-app/ui/src/components/ChatDrawer/ChatDrawer.test.tsx b/desktop-app/ui/src/components/ChatDrawer/ChatDrawer.test.tsxindex ecb596c08..9aec4b516 100644--- a/desktop-app/ui/src/components/ChatDrawer/ChatDrawer.test.tsx+++ b/desktop-app/ui/src/components/ChatDrawer/ChatDrawer.test.tsx@@ -82,6 +82,9 @@ describe('ChatDrawer', () => {expect(drawer.classList.contains('is-ready')).toBe(false)expect(getComputedStyle(drawer).opacity).toBe('0')expect(getComputedStyle(drawer).pointerEvents).toBe('none')+ // pointer-events:none only stops the mouse; `inert` is what also removes the+ // focusable handle/CTAs from the tab order while the drawer is not shown.+ expect(drawer.hasAttribute('inert')).toBe(true)})it('confines the composer reference submenu to the drawer interior, off the embed rect', () => {@@ -124,5 +127,6 @@ describe('ChatDrawer', () => {expect(drawer.classList.contains('is-ready')).toBe(true)expect(getComputedStyle(drawer).opacity).toBe('1')expect(getComputedStyle(drawer).pointerEvents).toBe('auto')+ expect(drawer.hasAttribute('inert')).toBe(false)})})diff --git a/desktop-app/ui/src/components/ChatDrawer/index.tsx b/desktop-app/ui/src/components/ChatDrawer/index.tsxindex 65c455c1d..0b48f85dd 100644--- a/desktop-app/ui/src/components/ChatDrawer/index.tsx+++ b/desktop-app/ui/src/components/ChatDrawer/index.tsx@@ -31,6 +31,12 @@ export function ChatDrawer({className={`chat-drawer${ready ? ' is-ready' : ''}${resizing ? ' is-resizing' : ''}`}aria-label="Chat"data-ready={ready ? 'true' : 'false'}+ // Not-ready is hidden with `opacity: 0; pointer-events: none`, which stops+ // the mouse but NOT the keyboard: a `tabIndex=0` under opacity:0 is still+ // focusable, so between mount and the embed's bounds-ack Tab could land on+ // the invisible resize handle / CTAs. `inert` takes the whole subtree out+ // of the tab order (and the a11y tree) until the drawer is actually shown.+ inert={!ready}><divclassName="chat-drawer__resize-handle"