Skip to content

The agent that grows with you

refactor(desktop): tighten the surface-var helper

Brooklyn Nicholsone7f4b95b4714
diff --git a/apps/desktop/src/app/chat/composer/status-stack/index.tsx b/apps/desktop/src/app/chat/composer/status-stack/index.tsx
index 8c779bbde55..10b7a0776bf 100644
--- a/apps/desktop/src/app/chat/composer/status-stack/index.tsx
+++ b/apps/desktop/src/app/chat/composer/status-stack/index.tsx
@@ -198,14 +198,12 @@ export function ComposerStatusStack({ queue, sessionId }: ComposerStatusStackPro
// height never sees it. Publish our own measured height — bucketed like the
// composer's, to avoid style invalidation churn — so the thread's
// last-message clearance can add it and the stack never hides messages.
- // Scoped to THIS chat surface: tiles render their own stack beside the
- // workspace pane, and a shared global would let the taller one dictate every
- // thread's padding (see surface-vars.ts).
+ // Scoped to THIS surface: tiles render their own stack (see surface-vars.ts).
useLayoutEffect(() => {
const el = stackRef.current
if (!visible || !el) {
- clearSurfaceVar(stackRef.current, STATUS_STACK_VAR)
+ clearSurfaceVar(el, STATUS_STACK_VAR)
return
}
diff --git a/apps/desktop/src/app/chat/surface-vars.test.ts b/apps/desktop/src/app/chat/surface-vars.test.ts
index 41b7c8ad3f3..438d36c75be 100644
--- a/apps/desktop/src/app/chat/surface-vars.test.ts
+++ b/apps/desktop/src/app/chat/surface-vars.test.ts
@@ -57,7 +57,7 @@ describe('per-surface measured-height vars', () => {
const orphan = document.createElement('div')
document.body.append(orphan)
- expect(chatSurfaceRoot(orphan)).toBeNull()
+ expect(chatSurfaceRoot(orphan)).toBe(document.documentElement)
setSurfaceVar(orphan, STATUS_STACK_VAR, '24px')
expect(document.documentElement.style.getPropertyValue(STATUS_STACK_VAR)).toBe('24px')
diff --git a/apps/desktop/src/app/chat/surface-vars.ts b/apps/desktop/src/app/chat/surface-vars.ts
index dfe9df96797..5176dc11375 100644
--- a/apps/desktop/src/app/chat/surface-vars.ts
+++ b/apps/desktop/src/app/chat/surface-vars.ts
@@ -16,27 +16,25 @@
* there is no single correct value to remeasure to.
*/
-/** Nearest enclosing chat surface, or `null` when the node is detached. */
-export function chatSurfaceRoot(el: Element | null): HTMLElement | null {
- return el?.closest<HTMLElement>('[data-chat-surface]') ?? null
-}
-
export const COMPOSER_HEIGHT_VAR = '--composer-measured-height'
export const COMPOSER_SURFACE_HEIGHT_VAR = '--composer-surface-measured-height'
export const STATUS_STACK_VAR = '--status-stack-measured-height'
/**
- * Set a measured-height var on the surface owning `el`. Falls back to the
- * document root so a composer rendered outside a chat surface (the popped-out
- * window) keeps behaving exactly as before.
+ * The surface owning `el`, falling back to the document root so a composer
+ * rendered outside a chat surface (the popped-out window) keeps behaving
+ * exactly as before.
*/
+export function chatSurfaceRoot(el: Element | null): HTMLElement {
+ return el?.closest<HTMLElement>('[data-chat-surface]') ?? document.documentElement
+}
+
+/** Publish a measured-height var on the surface owning `el`. */
export function setSurfaceVar(el: Element | null, name: string, value: string): void {
- const target = chatSurfaceRoot(el) ?? document.documentElement
- target.style.setProperty(name, value)
+ chatSurfaceRoot(el).style.setProperty(name, value)
}
/** Clear a measured-height var from the surface owning `el`. */
export function clearSurfaceVar(el: Element | null, name: string): void {
- const target = chatSurfaceRoot(el) ?? document.documentElement
- target.style.removeProperty(name)
+ chatSurfaceRoot(el).style.removeProperty(name)
}
diff --git a/apps/desktop/src/styles.css b/apps/desktop/src/styles.css
index 0b5ed5c70cb..919b5ff76ef 100644
--- a/apps/desktop/src/styles.css
+++ b/apps/desktop/src/styles.css
@@ -348,8 +348,7 @@
/* Space under last message vs overlay composer — driven by the measured composer height (see composer/index.tsx)
plus the out-of-flow status stack's measured height (see status-stack/index.tsx) when one is showing.
- Both inputs are republished per chat surface (see surface-vars.ts), and the calc is re-declared there so
- each surface resolves against its OWN measurements — a tile's tall stack must not pad another thread. */
+ These are the defaults; each chat surface re-declares the calc against its own measurements (see below). */
--status-stack-measured-height: 0px;
--thread-last-message-clearance: calc(var(--composer-measured-height) + var(--status-stack-measured-height) + 2rem);