Skip to content

fix(AppShell): agent sidebar sometimes paints with no background#324

Merged
I-am-nothing merged 1 commit into
mainfrom
fix/agent-sidebar-background
Jul 1, 2026
Merged

fix(AppShell): agent sidebar sometimes paints with no background#324
I-am-nothing merged 1 commit into
mainfrom
fix/agent-sidebar-background

Conversation

@I-am-nothing

Copy link
Copy Markdown
Contributor

Bug

The agent sidebar sometimes renders with no background (transparent panel — the page shows through). It reproduces on reload when the sidebar was left open, not on a fresh in-session open.

Root cause

The body's background is drawn as a single full-window shape by AgentSidebarHeader, gated on windowBodyHeight != null. That value is agentBodyH — the body's measured height. The body div itself is intentionally transparent (the shape supplies the fill), so agentBodyH === 0 ⇒ header falls back to a body-less cap ⇒ no background.

agentBodyH was measured by a ResizeObserver in an effect keyed on [isOpen]. But the body node mounts on isOpen && sidebarWidth > 0, and that condition can flip true without isOpen changing: on the reload-restore path open stays true from mount while the width seeds 0 → >0 (and the async width GET lands the same way). The effect never re-ran after the node mounted, so the observer never attached, agentBodyH stayed 0, and the sidebar had no background until an unrelated close+reopen toggled isOpen.

Fix

Attach the observer through a callback ref instead of a [isOpen]-keyed effect, so it fires exactly when the body node mounts/unmounts — it can never desync from the render condition. This fixes the class of bug (any mount trigger), not just this instance. StrictMode-safe (disconnects before re-observing; disconnects on null).

Verification

  • Adds a regression test: on a reload-restore open (open true from mount, width seeds after), the body node is observed. Pre-fix that mount went unobserved (test fails on old code).
  • pnpm typecheck green; pnpm test 786/786 pass.

Code-only — no version bump (kit rolls up to 0.6.0 separately). Touched files are lint-clean; the 2 pre-existing react-hooks/exhaustive-deps errors on main (SidebarProvider.tsx, useAgentSession.ts) are unrelated to this diff.

The agent sidebar sometimes rendered with no background. The body's
measured height feeds AgentSidebarHeader's single full-window shape (the
fill); when that height is 0 the header falls back to a body-less cap and
the panel paints with no background.

The height came from a ResizeObserver in an [isOpen]-keyed effect, but the
body node mounts on `isOpen && sidebarWidth > 0` — a condition that flips
true WITHOUT isOpen changing on the reload-restore path (open stays true
while the width seeds 0 -> >0, and the async width GET lands the same way).
The effect missed that mount, so the observer never attached, agentBodyH
stayed 0, and the background was missing until an unrelated close+reopen
toggled isOpen. A callback ref binds the observer to the actual DOM
mount/unmount, so it can never desync from the render condition.

Adds a regression test asserting the body is observed on a reload-restore
open (open=true from mount, width seeds after) — pre-fix that mount went
unobserved.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Storybook Preview: https://mirrorstack-ai.github.io/web-ui-kit/pr/324/

github-actions Bot added a commit that referenced this pull request Jul 1, 2026
@I-am-nothing I-am-nothing merged commit b970458 into main Jul 1, 2026
4 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in MirrorStack Platform Jul 1, 2026
github-actions Bot added a commit that referenced this pull request Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant