Skip to content

ui-react: size-only media queries move to CSS, with a container query for the stats bar #2600

Open

Description

@schlessera

Context

ui-react calls useMediaQuery 23 times (useMediaQuery, packages/ui-react/src/hooks/use-media-query.ts:10). Twenty of those calls change what renders: which tree mounts, an overlay variant, focus routing, or a capability. They stay JavaScript:

  • chat-page.tsx:145,149
  • handoff-sheet.tsx:88
  • graph-scene.tsx:84,682
  • graph-page.tsx:50,51,218
  • graph-controls.tsx:34
  • desktop-palette.tsx:49
  • settings-panel.tsx:52
  • file-panel.tsx:43
  • activity-page.tsx:72
  • composer-view.tsx:132
  • dictation-sheet.tsx:20
  • side-rail.tsx:59
  • session-list.tsx:119
  • use-color-scheme.ts:19
  • use-fine-pointer.ts:14
  • storage-tab.tsx:48: an overlay variant via storage-dialogs.tsx:50,214, plus a number that StorageMap lays out with

Three calls change only a size or a CSS class. Each costs a subscription and a re-render, and each answers the wrong question or answers in the wrong layer:

  1. StatsAnswer (wide, packages/ui-react/src/components/chat/stats/stats-answer.tsx:18) picks BarList's barWidth 120 or 56 (stats-answer.tsx:60). The comment says the choice is about the room the answer's column has, but the code asks for the viewport. The answer renders inside the chat column next to the rail and the sessions pane, so it should ask its container.
  2. ConversationStrip (shortScreen, packages/ui-react/src/components/voice/conversation-strip.tsx:13) only switches one row's height between 44 and 52 (conversation-strip.tsx:60).
  3. ComposerRow (shortScreen, packages/ui-react/src/components/chat/composer-row.tsx:66) only adds a class that hides two rows (composer-row.tsx:70-78).

Items 2 and 3 really are about viewport height, so they become CSS @media (max-height: 580px) rules, not container queries.

The kit already uses size container queries (packages/ui-kit/src/tokens.css:2012, :2188, :2318, :2330). BarList takes its track width only as an inline pixel number (trackStyle, packages/ui-kit/src/evidence/BarList.tsx:82-83), and a stylesheet cannot override that.

Guide css/size-aware-styling: "Using container queries is recommended because it makes components truly modular. You do not need to know where the component will live". Support for size container queries: Chrome 105, Firefox 110, all targets.

Scope

  • BarList reads its track width from a CSS custom property, with barWidth as the fallback: width: var(--bk-bar-track, <barWidth>px). The prop keeps its meaning for every existing caller.
  • StatsAnswer makes its root an inline-size container and sets --bk-bar-track: 120px inside an @container rule. Pick the threshold so that every existing stats layout and visual baseline keeps its current bar width. Drop the hook.
  • ConversationStrip and ComposerRow drop useMediaQuery. The 44/52 height and the hidden rows move to @media (max-height: 580px) rules keyed on the existing data attributes (data-conversation-strip, data-session-strip, data-pending-follow-ups). The voiceActive && voiceReview conditions stay as data attributes or classes that React sets.

Out of scope

  • The 20 calls listed above as staying JavaScript, including storage-tab.tsx's ResizeObserver (storage-tab.tsx:56-67), which feeds pixel sizes to StorageMap's layout.
  • session-list.tsx:119 (any-pointer: coarse). That is a pointer query, not a size query.
  • Changing any breakpoint value or any rendered size.
  • Removing useMediaQuery.

Acceptance criteria

  • git grep -n useMediaQuery -- packages/ui-react/src/components/chat/stats packages/ui-react/src/components/voice/conversation-strip.tsx packages/ui-react/src/components/chat/composer-row.tsx returns nothing, and the total call count drops from 23 to 20.
  • A real-browser layout test fails before the change and passes after. It mounts StatsAnswer in a 360px-wide container inside a 1280px-wide viewport and asserts a 56px bar track. Today the viewport query gives 120.
  • A real-browser layout test at 390×560, with voice review active, asserts that the strip's control row is 44px and the session strip is hidden. At 390×844 it asserts 52px and visible. It passes before and after, because behaviour is preserved.
  • bun run visual and the stats layout tests show no baseline change.

Verification

node scripts/visual.mjs --project=ui-react-layout --filter=<stats-and-strip-tests>
node scripts/visual.mjs --project=storybook --filter=BarList.stories
bun run visual
bun run test
bun run typecheck
bun run lint

Contract impact

  • This touches the integration contract, so it needs the contract label, a CONTRACT: commit prefix, and the doc updated in the same commit.
  • This changes a published package's behaviour, so it needs a changeset.

BarList gains an additive, optional custom-property hook. Kit component props are not listed in docs/integration-contract/package-api.md.

Activity

  1. added
    type: refactor
    area: ui-react
    area: ui-kit
    priority: p3
    agent-ready
    on Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readyarea: ui-kitarea: ui-reactpriority: p3type: refactor

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions