Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: portal the shared Drawer overlay to <body> (#4150)

Adam Eivybf7013937488
diff --git a/client/src/CLAUDE.md b/client/src/CLAUDE.md
index e4c42defc9..3ce95b1a9d 100644
--- a/client/src/CLAUDE.md
+++ b/client/src/CLAUDE.md
@@ -36,6 +36,7 @@ For the full "adding a new page" checklist (nav manifest entry shape, palette ac
- **Mobile `<select>` fallback + `TabPills`.** The tab bar is `client/src/components/ui/TabPills.jsx` (`mobileDropdown` collapses it to a `<select>` under `sm`) — **reuse it, never roll a new tab bar.** The `Drawer tabs` layout wires TabPills for you; a surface hosted in *both* a drawer and a page (like `ImageGenTab`) renders its own internal `<TabPills variant="pills" mobileDropdown>` instead so the same grouping works in either host.
- **Deep-linkable active tab.** Drive `activeTab` from a URL search param via `useDrawerTab(paramName, defaultTab, tabIds)` (`client/src/hooks/useDrawerTab.js`) so the open section is shareable/bookmarkable/reload-safe — the same "URL is the source of truth for what's open" rule as routed views. The caller owns the param name (`appTab`, `mediaTab`, …) so a page can host more than one drawer; pass the id list so a stale deep link degrades to `defaultTab` instead of a blank panel.
- **Long-lived forms** opt out of accidental dismissal with `closeOnEsc={false}` / `closeOnBackdrop={false}` so an Esc keystroke mid-edit doesn't discard the form.
+ - **The overlay is always portaled to `<body>` — never re-nest it.** The backdrop and panel are both `position:fixed`, and a `filter` / `backdrop-filter` / `transform` ancestor becomes their containing block; on the "glass" themes `index.css` gives every bordered/rounded `.bg-port-card` a `backdrop-filter`, so an inline drawer nested under a card was sized to the *card*, not the viewport (issue #4150). Portaling is unconditional rather than an opt-in flag, so no call site has to remember it — React still routes events and context through the React tree. The one thing the portal leaves behind is a **page-scoped CSS theming root written as descendant selectors** (`.cybercity-themed` in `index.css`): a caller inside one must pass that class as `portalClassName` (see `CitySettingsDrawer.jsx`). Same trap, same fix, for any new hand-rolled `fixed inset-0` overlay — portal it (`Modal`'s `usePortal`, `GalleryImagePicker.jsx`).
- **Worked examples:** `client/src/components/apps/EditAppDrawer.jsx` (built-in `tabs` layout, `size="lg"`, `useDrawerTab('appTab', …)`) and `client/src/components/settings/ImageGenTab.jsx` (internal `TabPills variant="pills"` sub-tabs, `useDrawerTab('mediaTab', …)`). The primitive is `Drawer.jsx`; the design record is `docs/plans/2026-07-01-drawer-ux-redesign.md`.
## Socket-driven UI
diff --git a/client/src/components/Drawer.jsx b/client/src/components/Drawer.jsx
index b234a35e66..68d0142dfa 100644
--- a/client/src/components/Drawer.jsx
+++ b/client/src/components/Drawer.jsx
@@ -1,4 +1,5 @@
import { useEffect, useRef, useState } from 'react';
+import { createPortal } from 'react-dom';
import { X } from 'lucide-react';
import { useScrollLock } from '../hooks/useScrollLock';
import useFocusTrap from '../hooks/useFocusTrap.js';
@@ -26,6 +27,18 @@ import TabPills from './ui/TabPills';
// child's own labeled sections over tabs (which hide inactive fields behind a
// click) — e.g. ImageGenSettingsForm's `grouped` prop in the pipeline image-gen
// drawers.
+//
+// The backdrop + panel are ALWAYS portaled to <body>. Both are `position:fixed`,
+// and a `filter` / `backdrop-filter` / `transform` ancestor becomes the
+// containing block for fixed descendants — so on the "glass" themes (where
+// `index.css` gives every bordered/rounded `.bg-port-card` a `backdrop-filter`)
+// an inline drawer nested under such a card was sized to the card instead of the
+// viewport. Portaling is unconditional rather than an opt-in flag so no call
+// site has to remember it; React still routes events and context through the
+// React tree, so nesting a Drawer deep in a page keeps working unchanged.
+// A caller sitting inside a page-scoped CSS theming root whose rules are written
+// as descendant selectors (e.g. `.cybercity-themed` in `index.css`) must pass
+// that class as `portalClassName`, since the portal leaves that ancestor behind.
// Desktop width brackets. Mobile is always `w-full`. `lg`/`xl` intentionally use
// more of the viewport (via extra breakpoints) so wide config forms can lay out
@@ -52,6 +65,7 @@ export default function Drawer({
closeOnEsc = true,
closeOnBackdrop = true,
closeLabel = 'Close settings',
+ portalClassName = '', // re-applies a page-scoped theming class inside the portal
}) {
useScrollLock(open);
@@ -81,7 +95,7 @@ export default function Drawer({
const resolvedWidth = widthClass || SIZE[size] || SIZE.sm;
const bodyClasses = `flex-1 overflow-y-auto p-4 ${bodyClassName}`.trim();
- return (
+ const overlay = (
<>
<div
className="fixed inset-0 z-40 bg-black/60"
@@ -144,4 +158,14 @@ export default function Drawer({
</aside>
</>
);
+
+ // SSR / non-DOM render falls back to rendering in place — there is no <body>
+ // to portal into, and the containing-block trap is a layout concern that only
+ // exists in a browser anyway.
+ if (typeof document === 'undefined') return overlay;
+
+ return createPortal(
+ portalClassName ? <div className={portalClassName}>{overlay}</div> : overlay,
+ document.body
+ );
}
diff --git a/client/src/components/Drawer.test.jsx b/client/src/components/Drawer.test.jsx
index 30e9afd82b..bbc87af854 100644
--- a/client/src/components/Drawer.test.jsx
+++ b/client/src/components/Drawer.test.jsx
@@ -134,4 +134,68 @@ describe('Drawer', () => {
expect(screen.getByRole('tabpanel').className).toContain('lg:grid-cols-2');
});
});
+
+ describe('portaled overlay', () => {
+ // A `backdrop-filter` ancestor becomes the containing block for
+ // position:fixed descendants. On the "glass" themes index.css gives every
+ // bordered/rounded `.bg-port-card` a backdrop-filter, so an inline drawer
+ // nested under such a card was sized to the card, not the viewport.
+ const renderInGlassCard = (props = {}) => render(
+ <div style={{ backdropFilter: 'blur(22px)' }} data-testid="glass-card">
+ <Drawer open onClose={() => {}} title="Edit App" {...props}><p>form body</p></Drawer>
+ </div>
+ );
+
+ it('portals both the backdrop and the panel out of a backdrop-filter ancestor', () => {
+ const { container } = renderInGlassCard();
+
+ const glassCard = screen.getByTestId('glass-card');
+ const dialog = screen.getByRole('dialog');
+ const backdrop = document.querySelector('[aria-hidden="true"]');
+
+ expect(document.body.contains(dialog)).toBe(true);
+ expect(glassCard.contains(dialog)).toBe(false);
+ // The backdrop is the trapped element the bug is named for — it must
+ // escape too, or it renders as a card-sized scrim instead of covering
+ // the viewport.
+ expect(glassCard.contains(backdrop)).toBe(false);
+ expect(container.querySelector('[role="dialog"]')).toBeNull();
+ expect(container.querySelector('[aria-hidden="true"]')).toBeNull();
+ // The glass card keeps only its own (empty) subtree.
+ expect(glassCard).toBeEmptyDOMElement();
+ });
+
+ it('keeps backdrop + Esc dismissal working through the portal', () => {
+ const onClose = vi.fn();
+ render(
+ <div style={{ backdropFilter: 'blur(22px)' }}>
+ <Drawer open onClose={onClose} title="X">b</Drawer>
+ </div>
+ );
+ fireEvent.click(document.querySelector('[aria-hidden="true"]'));
+ fireEvent.keyDown(window, { key: 'Escape' });
+ expect(onClose).toHaveBeenCalledTimes(2);
+ });
+
+ it('portals straight into <body> with no wrapper element by default', () => {
+ renderInGlassCard();
+ // Backdrop and panel are direct children of <body> — matching the shared
+ // Modal's portal shape.
+ expect(screen.getByRole('dialog').parentElement).toBe(document.body);
+ expect(document.querySelector('[aria-hidden="true"]').parentElement).toBe(document.body);
+ });
+
+ it('re-applies a page-scoped theming class inside the portal via portalClassName', () => {
+ // The City HUD palette remap in index.css is written as
+ // `.cybercity-themed <utility>` descendant selectors, which the portal
+ // would otherwise leave behind.
+ renderInGlassCard({ portalClassName: 'cybercity-themed' });
+
+ const wrapper = screen.getByRole('dialog').parentElement;
+ expect(wrapper.className).toBe('cybercity-themed');
+ expect(wrapper.parentElement).toBe(document.body);
+ // The backdrop shares the themed wrapper so the scrim is remapped too.
+ expect(wrapper.contains(document.querySelector('[aria-hidden="true"]'))).toBe(true);
+ });
+ });
});
diff --git a/client/src/components/city/CitySettingsDrawer.jsx b/client/src/components/city/CitySettingsDrawer.jsx
index 5c3f0f3ef0..b2c48c0b54 100644
--- a/client/src/components/city/CitySettingsDrawer.jsx
+++ b/client/src/components/city/CitySettingsDrawer.jsx
@@ -172,6 +172,11 @@ export default function CitySettingsDrawer({ open, onClose, qualityMode = 'manua
activeTab={activeTab}
onTabChange={setActiveTab}
closeLabel="Close city settings"
+ // Drawer portals to <body>, which leaves the page's `.cybercity-themed`
+ // root behind — and the City HUD palette remap in index.css is written as
+ // `.cybercity-themed <utility>` descendant selectors. Re-apply the class
+ // inside the portal so the panel keeps its themed ink/surfaces.
+ portalClassName="cybercity-themed"
>
{activeTab === 'performance' && (
<div className="space-y-5">