fix(desktop): HUD sizing — empty band, stranded exit chip, early stacking

Four things the band's content-sizing exposed, all of them stale assumptions
from when it was a full-window box.

A leftover `:focus-within` rule still painted the band's own background, so
focusing an empty session filled the whole window with a solid slab even though
the sheet had correctly collapsed to nothing.

The exit chip anchored to the band rather than the sheet, so on a short
transcript it floated in empty space at the window's corner. It now rides the
sheet, and drops clear of the bar when the layout is flipped.

Bottom clearance read `--composer-measured-height`, a surface var that never
reaches here, so it silently fell back to the root estimate and reserved ~20px
more than the bar occupies. The bar's real height is measured alongside the
band's.

Top-edge mode was never re-checked after the sheet started sizing itself: the
sheet stayed pinned to the bottom while the transcript hung from the top. Both
the anchor and the measurement now flip with the layout.
This commit is contained in:
Brooklyn Nicholson
2026-08-08 01:59:25 -05:00
parent d57927f3bb
commit 6ada733f9d
3 changed files with 56 additions and 21 deletions
@@ -8,7 +8,6 @@ import {
COMPOSER_SURFACE_HEIGHT_VAR,
setSurfaceVar
} from '@/app/chat/surface-vars'
import { useMediaQuery } from '@/hooks/use-media-query'
import { useResizeObserver } from '@/hooks/use-resize-observer'
import { COMPOSER_COMPACT_PILL_PX, COMPOSER_SINGLE_LINE_MAX_PX, COMPOSER_STACK_BREAKPOINT_PX } from '../composer-utils'
@@ -43,7 +42,6 @@ export function useComposerMetrics({
const [tight, setTight] = useState(false)
// Wider than `tight`: the pill goes icon-only before the row has to stack.
const [compactPill, setCompactPill] = useState(false)
const narrow = useMediaQuery('(max-width: 30rem)')
// Edge signals, not the live text: these only re-render when emptiness / the
// presence of a non-trailing newline actually flips, so typing within a line
@@ -191,7 +189,17 @@ export function useComposerMetrics({
}
}, [composerRef])
// Pill compacts on real width (tile/pane), OR when stacked for any reason
// (viewport-narrow / wrapped) so the controls row never over-runs.
return { compactPill: compactPill || narrow || tight, stacked: expanded || narrow || tight }
// Both decisions come from the composer's OWN measured width, never the
// viewport's. There used to be a `(max-width: 30rem)` media query in here as
// well, and it quietly outranked everything: any window under 480px stacked
// the row AND compacted the pill in the same instant, regardless of how much
// room the composer actually had. That collapsed the whole progressive ladder
// into one step for small windows — HUD mode is ~470px, so it never saw the
// ladder at all — and it disagreed with the measured breakpoints (320 to
// stack) by 160px. The ResizeObserver knows the real width; the viewport is
// not a proxy for it.
//
// The pill still compacts whenever the row stacks, so the controls row can't
// over-run once it has the width to itself.
return { compactPill: compactPill || tight, stacked: expanded || tight }
}
+25 -3
View File
@@ -174,9 +174,31 @@ export function HudShell() {
// Written straight to the element rather than through state: it changes on
// every stream flush, and the sheet resizing must not re-render the tree.
const rows = el?.querySelectorAll<HTMLElement>('[data-slot="aui_thread-content"] > *:not([data-slot])')
const top = rows?.length ? rows[0].getBoundingClientRect().top : null
const height = top === null || !el ? 0 : Math.max(0, el.getBoundingClientRect().bottom - top)
root.style.setProperty('--hud-band-height', `${Math.round(height)}px`)
const box = el?.getBoundingClientRect()
// Measured from the bar outward, so it flips with the layout: parked at
// the bottom the transcript grows up from the bar, parked at the top it
// hangs down from it.
const span =
!rows?.length || !box
? 0
: root.dataset.hudEdge === 'top'
? rows[rows.length - 1].getBoundingClientRect().bottom - box.top
: box.bottom - rows[0].getBoundingClientRect().top
root.style.setProperty('--hud-band-height', `${Math.max(0, Math.round(span))}px`)
// …and the bar's real height, which is what the thread has to clear.
// --composer-measured-height would be the obvious source, but it is a
// surface var that never lands here, so the clearance silently fell back
// to the root estimate and reserved ~20px more than the bar occupies —
// a visible hole under the last message.
const bar = root.querySelector<HTMLElement>('[data-slot="composer-dock"]')
if (bar) {
ro.observe(bar)
root.style.setProperty('--hud-bar-height', `${Math.round(bar.getBoundingClientRect().height)}px`)
}
}
// The viewport mounts async (lazy chat surface); poll briefly until it
+18 -13
View File
@@ -2392,6 +2392,10 @@ button[data-slot='aui_msg-reactions'] svg {
getNativeWindowHandle() and buys a cross-dissolve between frosted and sharp
rather than a true blur-radius ramp. Its own change, not this one. */
[data-hud-shell] [data-hud-glass] {
/* The exit chip rides this box, not the band — the band is the whole window,
so anchoring there left the chip stranded in empty space above a short
transcript. */
anchor-name: --hud-band;
position: absolute;
right: 0;
bottom: 0;
@@ -2399,8 +2403,8 @@ button[data-slot='aui_msg-reactions'] svg {
/* Grows up from the bar to fit the transcript, capped at the window. An empty
session measures 0 and the sheet collapses behind the bar, rather than
painting a full-height slab with nothing in it. The extra is breathing room
above the first row so the fade has somewhere to happen. */
height: min(100%, calc(var(--hud-band-height, 0px) + 2rem));
above the first row so the fade has somewhere to land. */
height: min(100%, calc(var(--hud-band-height, 0px) + 0.75rem));
z-index: 0;
pointer-events: none;
border-radius: 0.75rem 0.75rem 0 0;
@@ -2430,6 +2434,7 @@ button[data-slot='aui_msg-reactions'] svg {
interpolates. Blown up and pinned to the bottom, the band only ever shows the
gradient's solid end. Reveal-speed both ways, so letting go of the composer
brings the ramp straight back instead of waiting out the fade's hold. */
[data-hud-shell]:focus-within [data-hud-glass],
[data-hud-shell]:focus-within [data-slot='aui_thread-viewport'] {
-webkit-mask-size: 100% 600%;
mask-size: 100% 600%;
@@ -2441,6 +2446,8 @@ button[data-slot='aui_msg-reactions'] svg {
}
[data-hud-shell][data-hud-edge='top'] [data-hud-glass] {
top: 0;
bottom: auto;
border-radius: 0 0 0.75rem 0.75rem;
}
@@ -2459,11 +2466,6 @@ button[data-slot='aui_msg-reactions'] svg {
transition-delay: 0s;
}
/* Typing: the band goes fully solid — viz2d's focus step, taken to its end. */
[data-hud-shell]:focus-within [data-slot='composer-bounds'] {
background: var(--dt-background) !important;
}
/* User messages ride the band like every other line. In the app each sticky
user row paints an OPAQUE chat-surface slab behind it (so a stuck bubble can
slide over scrolled text) and the bubble is solid --dt-user-bubble — inside
@@ -2574,7 +2576,7 @@ button[data-slot='aui_msg-reactions'] svg {
}
[data-hud-shell][data-hud-edge='top'] [data-slot='aui_thread-content'] {
padding-block-start: calc(var(--composer-measured-height) + 0.25rem) !important;
padding-block-start: calc(var(--hud-bar-height, var(--composer-fallback-height)) + 0.25rem) !important;
}
[data-hud-shell][data-hud-edge='top'] [data-slot='aui_thread-viewport'] {
@@ -2641,7 +2643,7 @@ button[data-slot='aui_msg-reactions'] svg {
gap between the last message and the composer. */
[data-hud-shell] [data-slot='aui_thread-content'] {
padding-inline: 0.6rem !important;
padding-block: 0.8rem 0.25rem !important;
padding-block: 0.35rem 0.25rem !important;
/* A chat frame fills from the bottom. The docked thread hangs from the top
because it is always taller than its content is short; the band is a few
lines tall, so a two-message conversation left a dead gap between the last
@@ -2662,7 +2664,7 @@ button[data-slot='aui_msg-reactions'] svg {
measured from the live dock, so it tracks the composer growing to two, three,
ten rows with no hairline and no hole. */
[data-hud-shell] [data-chat-surface] {
--thread-last-message-clearance: var(--composer-measured-height);
--thread-last-message-clearance: var(--hud-bar-height, var(--composer-fallback-height));
}
/* Same for the dock's own bottom pad — this var also feeds
@@ -2808,9 +2810,6 @@ button[data-slot='aui_msg-reactions'] svg {
the corner with its own margin reads as intentional. anchor() to the band:
calc()-based attempts drifted because the composer's measured vars are
inline-scoped and stale outside [data-chat-surface]. */
[data-hud-shell] [data-slot='composer-bounds'] {
anchor-name: --hud-band;
}
[data-hud-shell] [data-hud-exit] {
position-anchor: --hud-band;
@@ -2839,6 +2838,12 @@ button[data-slot='aui_msg-reactions'] svg {
pointer-events: auto;
}
/* Flipped, the sheet's top corner is behind the bar — drop the chip clear of
it so it stays in the transcript rather than under the composer. */
[data-hud-shell][data-hud-edge='top'] [data-hud-exit] {
top: calc(anchor(top) + var(--hud-bar-height, var(--composer-fallback-height)) + 0.5rem);
}
[data-hud-shell][data-hud-recent] [data-hud-exit],
[data-hud-shell]:focus-within [data-hud-exit] {
opacity: 0.75;