Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(desktop): repair universal-tabs titlebar, drawer stacking, and chat nav

Diego Zacariasfc3217d04e3c
diff --git a/desktop-app/ui/src/App.tsx b/desktop-app/ui/src/App.tsx
index 739340f51..3f68666ac 100644
--- a/desktop-app/ui/src/App.tsx
+++ b/desktop-app/ui/src/App.tsx
@@ -281,6 +281,10 @@ export function App() {
// drawer follows the app content down when the sandbox-ui header wraps (narrow
// window). 0 means "not measured yet" -> the CSS fallback (64px) applies.
const [chatDrawerEmbedTop, setChatDrawerEmbedTop] = React.useState<number | null>(null)
+ // Measured bottom of the global tab strip, published as the rail top on DOM
+ // tabs so the fixed chat drawer starts BELOW the strip (app tabs use the
+ // embed-slot top instead). 0/null means "not measured yet" -> the CSS fallback.
+ const [chatDrawerContentTop, setChatDrawerContentTop] = React.useState<number | null>(null)
const [chatSwitcherFocusRequestId, setChatSwitcherFocusRequestId] = React.useState(0)
const [availableSandboxUiApps, setAvailableSandboxUiApps] = React.useState<ActiveSandboxUiApp[]>(
[]
@@ -699,10 +703,12 @@ export function App() {
// flicker, and never the "inert forever" trap where a DOM tab waits for a
// bounds ack that never arrives.
const drawerReady = drawerHasEmbed ? chatDrawerReady : chatDrawerVisible
- // The rail follows the embed's measured header top only on app tabs; DOM tabs
- // pass null so the shell uses its static CSS fallback (§A2 — never consume an
- // embed measurement that will not arrive on a DOM tab).
- const drawerRailTop = drawerHasEmbed ? chatDrawerEmbedTop : null
+ // The rail starts below the header on both tab kinds: app tabs follow the
+ // embed's measured header top; DOM tabs follow the measured bottom of the
+ // global tab strip (both sit below the strip). The static 64px CSS fallback
+ // predates the global strip and now lands mid-strip, so a DOM tab that fell
+ // back to it would hide the strip's right tabs behind the drawer.
+ const drawerRailTop = drawerHasEmbed ? chatDrawerEmbedTop : chatDrawerContentTop
// The notification tray's drawer form occupies the same fixed right-rail rect
// as the chat drawer, so it only takes drawer form when the chat drawer is NOT
// visible; while the chat drawer is up it reverts to its popover/overlay form
@@ -965,6 +971,31 @@ export function App() {
setChatDrawerReady(false)
}, [activeSandboxUiApp?.appRef, chatDrawerVisible])
+ // On a DOM tab the drawer has no embed slot to anchor to; measure the global
+ // tab strip's bottom edge (via layout effect so the rail is placed before the
+ // first paint, no flash) and publish it as the rail top so the drawer docks
+ // BELOW the strip — matching app tabs, where the embed-slot top already does.
+ // Cleared for app tabs / a hidden drawer, which fall back to the embed top.
+ React.useLayoutEffect(() => {
+ if (!chatDrawerVisible || drawerHasEmbed) {
+ setChatDrawerContentTop(null)
+ return
+ }
+ const strip = contentPanelRef.current?.querySelector('.chat-view-tabs')
+ if (!strip) {
+ setChatDrawerContentTop(null)
+ return
+ }
+ const measure = () => {
+ setChatDrawerContentTop(Math.round(strip.getBoundingClientRect().bottom))
+ }
+ measure()
+ if (typeof ResizeObserver === 'undefined') return
+ const observer = new ResizeObserver(measure)
+ observer.observe(strip)
+ return () => observer.disconnect()
+ }, [chatDrawerVisible, drawerHasEmbed])
+
// 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`
diff --git a/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx b/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx
index 49b5ee32d..56b7ff3c1 100644
--- a/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx
+++ b/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx
@@ -1256,6 +1256,49 @@ describe('App chat drawer — universal availability (mini-spec 04a)', () => {
expect(drawer!.hasAttribute('inert')).toBe(false)
})
+ // T5 invariant — on a DOM/files tab (no embed to measure) the drawer must dock
+ // BELOW the global tab strip, so its right tabs are never hidden behind the
+ // drawer. App measures the strip's bottom edge and publishes it as the rail's
+ // `--rail-top`; without the fix the rail fell back to the static 64px CSS
+ // fallback (which lands mid-strip) and covered the strip's right tabs.
+ it('docks the DOM-tab drawer below the measured tab strip, not the 64px fallback (T5)', () => {
+ currentController = makeController({
+ selectedAgent: 'alpha',
+ activeChatId: 'chat-1',
+ navItem: DESKTOP_ROUTES.files,
+ chatList: CHAT_LIST,
+ } as Partial<AppController>)
+ const { container } = render(<App />)
+ expect(appHeaderHarness.props?.drawerAvailable).toBe(true)
+
+ // jsdom lays nothing out (getBoundingClientRect is all-zero), so give the
+ // global tab strip a measurable bottom edge. The rail must anchor to THIS,
+ // below the strip, never the static 64px fallback.
+ const strip = container.querySelector('.chat-view-tabs') as HTMLElement
+ expect(strip).not.toBeNull()
+ strip.getBoundingClientRect = () =>
+ ({
+ bottom: 128,
+ top: 40,
+ height: 88,
+ width: 0,
+ left: 0,
+ right: 0,
+ x: 0,
+ y: 40,
+ toJSON: () => ({}),
+ }) as DOMRect
+
+ act(() => appHeaderHarness.props?.onToggleChatDrawer?.())
+
+ const rail = document.querySelector('.right-rail-shell') as HTMLElement
+ expect(rail).not.toBeNull()
+ expect(rail.getAttribute('data-occupant')).toBe('chat-drawer')
+ // Anchored to the strip's measured bottom (128px), not the mid-strip 64px
+ // fallback that would hide the strip's right tabs behind the drawer.
+ expect(rail.style.getPropertyValue('--rail-top')).toBe('128px')
+ })
+
// R5 + DEC-2: the drawer is global; switching between non-chat kinds keeps it
// open and never lets the chat reconcile steal focus onto a chat tab.
it('keeps the drawer intact across non-chat tab switches without stealing focus (R5/DEC-2)', () => {
diff --git a/desktop-app/ui/src/hooks/__tests__/useAppController.workspaceTabs.test.tsx b/desktop-app/ui/src/hooks/__tests__/useAppController.workspaceTabs.test.tsx
index 898e77220..f1812314c 100644
--- a/desktop-app/ui/src/hooks/__tests__/useAppController.workspaceTabs.test.tsx
+++ b/desktop-app/ui/src/hooks/__tests__/useAppController.workspaceTabs.test.tsx
@@ -61,6 +61,50 @@ describe('useAppController — universal tab store ports', () => {
expect(active?.chat?.agentRef).toBe('agent-x')
})
+ // (a2) Navigating back to chat RESUMES the existing conversation instead of
+ // appending a fresh blank chat on every click. Regression for the "each click
+ // on the chats nav opens a NEW chat" bug: the parent unconditionally ran
+ // `handleSelectChatAgent(latestAgent, { selectLatest: false })`, which appended
+ // a blank chat tab whenever the focused chat was a real conversation.
+ it('resumes the existing conversation (no new chat tab) when navigating back to chat', async () => {
+ installAppControllerClerum({ agentNames: ['agent-x'] })
+ const app = renderAppController()
+ unmount = app.unmount
+
+ await waitFor(() => expect(app.result.current.isAuthenticated).toBe(true))
+ await waitFor(() => expect(app.result.current.initialExperienceLoading).toBe(false))
+
+ // Open a real conversation, then leave the chat route for a DOM tab.
+ act(() => {
+ app.result.current.handleSelectChatAgent('agent-x', { chatId: 'chat-1', selectLatest: false })
+ })
+ await waitFor(() => expect(app.result.current.activeChatId).toBe('chat-1'))
+ const chatTabsBefore = app.result.current.workspaceTabs.tabs.filter(
+ tab => tab.kind === 'chat'
+ ).length
+
+ act(() => {
+ app.result.current.handleNavSelect(DESKTOP_ROUTES.files)
+ })
+ expect(app.result.current.navItem).toBe(DESKTOP_ROUTES.files)
+
+ // Click "chats": must re-activate chat-1, not spawn a new blank chat.
+ act(() => {
+ app.result.current.handleNavSelect(DESKTOP_ROUTES.chat)
+ })
+
+ expect(app.result.current.navItem).toBe(DESKTOP_ROUTES.chat)
+ expect(app.result.current.activeChatId).toBe('chat-1')
+ const active = activeWorkspaceTab(app.result.current.workspaceTabs)
+ expect(active?.kind).toBe('chat')
+ expect(active?.chat?.chatId).toBe('chat-1')
+ // No extra chat tab was appended.
+ const chatTabsAfter = app.result.current.workspaceTabs.tabs.filter(
+ tab => tab.kind === 'chat'
+ ).length
+ expect(chatTabsAfter).toBe(chatTabsBefore)
+ })
+
// (b) A pending chat selection survives a tab/route change: selecting a chat
// with keepNavItem while on the apps route records the pending selection, and
// the agent-selection effect replays it (the chat actually loads) without
diff --git a/desktop-app/ui/src/hooks/domain/useNavigationController.ts b/desktop-app/ui/src/hooks/domain/useNavigationController.ts
index d769adefe..7387e64a6 100644
--- a/desktop-app/ui/src/hooks/domain/useNavigationController.ts
+++ b/desktop-app/ui/src/hooks/domain/useNavigationController.ts
@@ -59,15 +59,31 @@ export function useNavigationController() {
// Ensure a chat tab is active (navItem → chat this commit) without agent
// logic: keep the active chat tab, else focus the last chat tab, else seed a
// blank one. Agent selection is layered on by `handleSelectChatAgent`.
- const focusChatSection = useCallback(() => {
+ //
+ // This precedence is the SINGLE source of "which chat did the nav focus":
+ // it RETURNS the focused conversation's identity (`agentRef`/`chatId`) when a
+ // real chat is focused, or `null` when it keeps/seeds a blank chat. The caller
+ // (`useAppController.handleNavSelect`) loads exactly that value instead of
+ // re-deriving the same rule in its own layer, so the loaded chat can never
+ // drift from the focused one (D4).
+ const focusChatSection = useCallback((): { agentRef: string; chatId: string } | null => {
setAppsPickerActive(false)
- setWorkspaceTabs(current => {
- const active = activeWorkspaceTab(current)
- if (active?.kind === 'chat') return current
- const lastChat = [...current.tabs].reverse().find(tab => tab.kind === 'chat')
- if (lastChat) return { ...current, activeTabId: lastChat.id }
- return newChatTab(current, nextWorkspaceTabId(), null)
- })
+ const current = workspaceTabsRef.current
+ const active = activeWorkspaceTab(current)
+ const target =
+ active?.kind === 'chat'
+ ? active
+ : [...current.tabs].reverse().find(tab => tab.kind === 'chat')
+ if (target) {
+ setWorkspaceTabs(state =>
+ state.activeTabId === target.id ? state : { ...state, activeTabId: target.id }
+ )
+ return target.chat?.agentRef && target.chat.chatId
+ ? { agentRef: target.chat.agentRef, chatId: target.chat.chatId }
+ : null
+ }
+ setWorkspaceTabs(state => newChatTab(state, nextWorkspaceTabId(), null))
+ return null
}, [nextWorkspaceTabId])
/**
@@ -111,29 +127,32 @@ export function useNavigationController() {
// Base section navigation: every legacy `handleNavSelect(route)` call-site
// routes here and becomes an open/focus tab action (the single writer). For
// `chat`/`agents` it also clears `selectedAgent` exactly as before.
+ // Returns the chat `focusChatSection` focused (for the chat route) so the
+ // coordinator can load exactly that conversation; `null` for every other route
+ // and for a blank/seeded chat.
const handleNavSelect = useCallback(
- (item: NavItem) => {
+ (item: NavItem): { agentRef: string; chatId: string } | null => {
if (item === DESKTOP_ROUTES.chat) {
setSelectedAgent(null)
setSelectedAgentRoute(AGENT_WORKSPACE_ROUTES.connectors)
- focusChatSection()
- return
+ return focusChatSection()
}
if (item === DESKTOP_ROUTES.apps) {
showAppsPicker()
- return
+ return null
}
if (item === DESKTOP_ROUTES.files) {
openFilesSection()
- return
+ return null
}
const section = settingsSectionForRoute(item)
- if (!section) return
+ if (!section) return null
if (section === 'agents') {
setSelectedAgent(null)
setSelectedAgentRoute(AGENT_WORKSPACE_ROUTES.connectors)
}
openSettingsSection(section)
+ return null
},
[focusChatSection, openFilesSection, openSettingsSection, showAppsPicker]
)
diff --git a/desktop-app/ui/src/hooks/useAppController.ts b/desktop-app/ui/src/hooks/useAppController.ts
index 20c9b5e7a..a000b6c2a 100644
--- a/desktop-app/ui/src/hooks/useAppController.ts
+++ b/desktop-app/ui/src/hooks/useAppController.ts
@@ -985,8 +985,23 @@ export function useAppController() {
// ─── Cross-domain: handleNavSelect (extended) ───
const handleNavSelect = useCallback(
(item: NavItem) => {
- nav.handleNavSelect(item)
+ const focusedChat = nav.handleNavSelect(item)
if (item === DESKTOP_ROUTES.chat) {
+ // `nav.handleNavSelect` owns the "which chat did this focus" precedence
+ // (active chat → last chat tab → blank) and RETURNS it. Load exactly that:
+ // an existing conversation is re-activated in place (dedupes by chatId —
+ // no new tab), so clicking "chats" resumes the open conversation instead of
+ // appending a fresh blank chat on every click. Only when the nav focused a
+ // blank/absent chat (`null`) do we pre-select the latest agent. No second
+ // copy of the precedence lives here — that seam duplication (D4) would let
+ // the loaded chat drift from the focused one if the rule ever changed.
+ if (focusedChat) {
+ handleSelectChatAgent(focusedChat.agentRef, {
+ chatId: focusedChat.chatId,
+ selectLatest: false,
+ })
+ return
+ }
const latestAgent = pickLatestAgent(agentsData.agentNames, activity.agentLastActiveByAgent)
if (latestAgent) {
handleSelectChatAgent(latestAgent, { selectLatest: false })
diff --git a/desktop-app/ui/src/styles.css b/desktop-app/ui/src/styles.css
index 30e3658e2..0f46c38a3 100644
--- a/desktop-app/ui/src/styles.css
+++ b/desktop-app/ui/src/styles.css
@@ -13388,14 +13388,13 @@ pre {
}
/* Chat-drawer toggle (mini-spec 04a §C): a ghost control between the search and
- the bell, styled like the titlebar bell. `margin-left: auto` collapses the
- free space to its left so the toggle and the utilities cluster (which also
- carries margin-left:auto) sit together at the right, the toggle immediately
- left of the bell with the top-bar gap. */
-.top-bar .chat-drawer-toggle {
- margin-left: auto;
-}
-
+ the bell, styled like the titlebar bell. In the title bar the whole cluster
+ is packed to the right by `.window-titlebar__actions .top-bar`'s
+ `justify-content: flex-end` (search/toggle/bell are all `flex: 0 0 auto` with
+ `margin-left: 0`), so the toggle sits in flow between the search and the bell
+ with the top-bar gap — it must NOT carry a `margin-left: auto`, which would
+ absorb the row's free space and shove the search pill to the far left, on top
+ of the app's leading actions. */
.window-titlebar__actions .chat-drawer-toggle {
width: 30px;
height: 30px;
@@ -13403,6 +13402,10 @@ pre {
border-color: transparent;
background: transparent;
box-shadow: none;
+ /* The root title bar is the only `-webkit-app-region: drag` band; every
+ clickable control carves itself out as `no-drag` (see .window-titlebar__leading)
+ or the OS swallows its clicks for window dragging. */
+ -webkit-app-region: no-drag;
}
.window-titlebar__actions .chat-drawer-toggle svg {
@@ -16529,6 +16532,12 @@ pre {
}
/* Keyboard-first chat view tabs */
.chat-view-tabs {
+ /* The strip is now a global sibling ABOVE the per-kind seam (mini-spec 03 §3),
+ no longer nested in `.chat-view-workspace` — which is where this token is
+ otherwise declared. Declare it here too so the strip's own baseline shelf
+ (`::after`) and the inactive-tab borders keep resolving on every route. */
+ --chat-view-selected-border: rgba(var(--accent-rgb), 0.25);
+
flex: 0 0 auto;
display: flex;
min-width: 0;