Skip to content

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

TypeScript

fix(desktop-app): align the chat drawer top with the measured embed slot

Diego Zacariasa83fe33109e3
diff --git a/desktop-app/ui/src/App.tsx b/desktop-app/ui/src/App.tsx
index 4bac2bd56..1ef5fad63 100644
--- a/desktop-app/ui/src/App.tsx
+++ b/desktop-app/ui/src/App.tsx
@@ -262,6 +262,10 @@ export function App() {
const [notificationDrawerReady, setNotificationDrawerReady] = React.useState(false)
const [chatDrawerOpen, setChatDrawerOpen] = React.useState(false)
const [chatDrawerReady, setChatDrawerReady] = React.useState(false)
+ // Measured top of the embed slot, published as `--chat-drawer-top` so the fixed
+ // 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(0)
const [chatSwitcherFocusRequestId, setChatSwitcherFocusRequestId] = React.useState(0)
const [availableSandboxUiApps, setAvailableSandboxUiApps] = React.useState<ActiveSandboxUiApp[]>(
[]
@@ -2013,7 +2017,14 @@ export function App() {
}${chatDrawerVisible ? ' content-panel--chat-drawer-open' : ''}`}
style={
chatDrawerVisible
- ? { '--chat-drawer-width': `${chatDrawerResize.width}px` }
+ ? {
+ '--chat-drawer-width': `${chatDrawerResize.width}px`,
+ // Only publish the measured top once we have one;
+ // when 0 (pre-measure/tests) the CSS fallback applies.
+ ...(chatDrawerEmbedTop > 0
+ ? { '--chat-drawer-top': `${chatDrawerEmbedTop}px` }
+ : {}),
+ }
: undefined
}
>
@@ -2087,6 +2098,7 @@ export function App() {
onEmbeddedAppBack={handleSandboxUiClosed}
onEmbeddedAppRemoved={handleSandboxUiRemoved}
onEmbedBoundsApplied={handleSandboxUiBoundsApplied}
+ onEmbedSlotTopChange={setChatDrawerEmbedTop}
onNotify={vm.pushToast}
onShortcutOpenResult={handleSandboxUiShortcutOpenResult}
/>
diff --git a/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx b/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx
index c6d829412..254c1bb61 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?: boolean
onToggleChatDrawer?: () => void
onEmbeddedAppMounted?: () => void
+ onEmbedSlotTopChange?: (topPx: number) => void
},
}))
const appHeaderHarness = vi.hoisted(() => ({
@@ -591,4 +592,28 @@ describe('App chat drawer — narrow-width suppression (mini-spec 05)', () => {
expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(false)
expect(screen.queryByRole('button', { name: 'Open chats' })).toBeNull()
})
+
+ it('publishes --chat-drawer-top from the measured embed slot, falling back until measured', () => {
+ render(<App />)
+
+ act(() => {
+ sidebarHarness.props?.onOpenSandboxUiApp?.({
+ appRef: 'ns/app',
+ label: 'App',
+ defaultPath: '/',
+ })
+ })
+ expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(true)
+
+ const panel = document.querySelector('.content-panel') as HTMLElement
+ expect(panel.className).toContain('content-panel--chat-drawer-open')
+ // The width var is always present while docked; the top var stays absent until
+ // the embed reports a measured top, so the CSS 64px fallback applies.
+ expect(panel.style.getPropertyValue('--chat-drawer-width')).not.toBe('')
+ expect(panel.style.getPropertyValue('--chat-drawer-top')).toBe('')
+
+ // The embed reports a wrapped-header top through the real callback path.
+ act(() => sandboxUiPageHarness.props?.onEmbedSlotTopChange?.(140))
+ expect(panel.style.getPropertyValue('--chat-drawer-top')).toBe('140px')
+ })
})
diff --git a/desktop-app/ui/src/pages/SandboxUiPage.tsx b/desktop-app/ui/src/pages/SandboxUiPage.tsx
index 31c81e4c9..928ef15bb 100644
--- a/desktop-app/ui/src/pages/SandboxUiPage.tsx
+++ b/desktop-app/ui/src/pages/SandboxUiPage.tsx
@@ -112,8 +112,13 @@ function useEmbedBounds(
enabled: boolean,
parked: boolean,
refreshKey: string | number,
- onBoundsApplied?: () => void
+ onBoundsApplied?: () => void,
+ onSlotTopChange?: (topPx: number) => void
): void {
+ // Dedupe the emitted slot-top across pushes AND across effect re-runs, so a
+ // resize/scroll storm (or a dep change) never churns the parent's state when
+ // the measured top is unchanged.
+ const lastEmittedTopRef = useRef<number | null>(null)
useLayoutEffect(() => {
if (!enabled) return
const target = ref.current
@@ -124,6 +129,13 @@ function useEmbedBounds(
cancelAnimationFrame(raf)
raf = requestAnimationFrame(() => {
const rect = target.getBoundingClientRect()
+ if (onSlotTopChange) {
+ const top = Math.round(rect.top)
+ if (lastEmittedTopRef.current !== top) {
+ lastEmittedTopRef.current = top
+ onSlotTopChange(top)
+ }
+ }
void window.clerum.sandboxUi
.setBounds(boundsFromRect(rect))
.then(() => onBoundsApplied?.())
@@ -141,7 +153,7 @@ function useEmbedBounds(
window.removeEventListener('resize', push)
window.removeEventListener('scroll', push, true)
}
- }, [parked, ref, enabled, onBoundsApplied, refreshKey])
+ }, [parked, ref, enabled, onBoundsApplied, onSlotTopChange, refreshKey])
}
const APP_PAGE_SIZE = 6
@@ -167,6 +179,7 @@ export function SandboxUiPage({
onEmbeddedAppBack,
onEmbeddedAppRemoved,
onEmbedBoundsApplied,
+ onEmbedSlotTopChange,
onNotify,
onShortcutOpenResult,
}: SandboxUiPageProps = {}) {
@@ -489,7 +502,8 @@ export function SandboxUiPage({
launch.kind === 'mounted' || launch.kind === 'minting',
shellOverlayOpen,
boundsRefreshKey,
- onEmbedBoundsApplied
+ onEmbedBoundsApplied,
+ onEmbedSlotTopChange
)
// Native WebContentsView content always paints above renderer DOM. Capture
diff --git a/desktop-app/ui/src/pages/SandboxUiPage.types.ts b/desktop-app/ui/src/pages/SandboxUiPage.types.ts
index 7cee6f576..e41d63bec 100644
--- a/desktop-app/ui/src/pages/SandboxUiPage.types.ts
+++ b/desktop-app/ui/src/pages/SandboxUiPage.types.ts
@@ -37,6 +37,7 @@ export type SandboxUiPageProps = {
onEmbeddedAppBack?: () => void
onEmbeddedAppRemoved?: () => void
onEmbedBoundsApplied?: () => void
+ onEmbedSlotTopChange?: (topPx: number) => void
onNotify?: (message: string, tone: Tone) => void
onShortcutOpenResult?: (
requestId: number,
diff --git a/desktop-app/ui/src/pages/__tests__/SandboxUiPage.test.tsx b/desktop-app/ui/src/pages/__tests__/SandboxUiPage.test.tsx
index e2708d8d5..7d0911cec 100644
--- a/desktop-app/ui/src/pages/__tests__/SandboxUiPage.test.tsx
+++ b/desktop-app/ui/src/pages/__tests__/SandboxUiPage.test.tsx
@@ -779,6 +779,40 @@ describe('SandboxUiPage', () => {
})
})
+ it('publishes the measured embed slot top through onEmbedSlotTopChange', async () => {
+ sandboxUi.listApps.mockResolvedValueOnce({
+ apps: [
+ {
+ appRef: 'sandbox-recipes/sales-crm',
+ title: "Andy's Sales CRM",
+ defaultPath: '/',
+ ready: true,
+ phase: 'active',
+ updatedAt: null,
+ },
+ ],
+ })
+ sandboxUi.open.mockResolvedValueOnce(undefined)
+ const onEmbedSlotTopChange = vi.fn()
+
+ render(<SandboxUiPage onEmbedSlotTopChange={onEmbedSlotTopChange} />)
+
+ fireEvent.click(await screen.findByRole('button', { name: "Open Andy's Sales CRM" }))
+ await screen.findByRole('button', { name: 'Back to apps' })
+
+ // The slot rect (getBoundingClientRect mock -> top: 12) flows through the real
+ // useEmbedBounds push, so the callback fires with Math.round(rect.top) = 12.
+ await waitFor(() => {
+ expect(onEmbedSlotTopChange).toHaveBeenCalledWith(12)
+ })
+ const calls = onEmbedSlotTopChange.mock.calls.length
+
+ // A push that measures the same top must NOT re-emit (dedupe against churn).
+ fireEvent.scroll(window)
+ await new Promise(resolve => window.setTimeout(resolve, 0))
+ expect(onEmbedSlotTopChange.mock.calls.length).toBe(calls)
+ })
+
it('reloads the embed in place when the Refresh button is clicked (no navigate-away needed)', async () => {
sandboxUi.listApps.mockResolvedValueOnce({
apps: [
diff --git a/desktop-app/ui/src/styles.css b/desktop-app/ui/src/styles.css
index 5b52bd6ba..903842b49 100644
--- a/desktop-app/ui/src/styles.css
+++ b/desktop-app/ui/src/styles.css
@@ -12683,7 +12683,11 @@ pre {
.chat-drawer {
position: fixed;
- top: calc(var(--space-4) + 36px + var(--space-2));
+ /* Follow the measured top of the embed slot (`--chat-drawer-top`, published by
+ App from useEmbedBounds) so the drawer stays aligned when the sandbox-ui
+ header wraps in a narrow window. The fallback keeps the pre-measure/test
+ behavior: a single-row header at space-4 + 36px + space-2 = 64px. */
+ top: var(--chat-drawer-top, calc(var(--space-4) + 36px + var(--space-2)));
right: var(--space-4);
bottom: var(--space-4);
width: var(--chat-drawer-width);