Skip to content

fix(sidebar): portal the submenu out of the scrollable menu - #1902

Merged
vastsa merged 2 commits into
vastsa:mainfrom
SeanLiu326:fix/sidebar-submenu-portal
Oct 26, 2026
Merged

vastsa merged 2 commits into
vastsa:mainfrom
SeanLiu326:fix/sidebar-submenu-portal

Conversation

@SeanLiu326

Copy link
Copy Markdown
Contributor

What this fixes

Fixes #1896 — the sidebar's second-level menu (Git / copy / danger zone) renders away from its trigger and stretches the menu into a horizontal scrollbar once anything on the root menu creates a containing block for position: fixed descendants.

Root cause

The child panel is a DOM child of the root menu (SidebarMenuPanel.tsx), while both are position: fixed. .sidebar-row-menu is also overflow-y: auto with a max-height. A fixed child is viewport-anchored only while no ancestor creates a containing block; the moment one appears — the reporter's build carries backdrop-filter: blur(22px) saturate(1.55) on .sidebar-floating-menu, and a transform, filter or contain would do the same — the child is laid out relative to the menu, so placeSidebarSubmenu()'s viewport coordinates get the menu's own offset added on top, and the child lands inside the menu's scroll area.

Measured in Chromium (not inferred)

I built the exact CSS from sessions.css and measured getBoundingClientRect() + scrollWidth/clientWidth in Chromium, with and without the reported declaration:

variant child position (expected 448,299) root scrollWidth / clientWidth
current CSS 448, 299 ✅ 194 / 194 ✅
+ backdrop-filter on the menu 1980, 410 ❌ 1274 / 179 ❌

1980−448 = 900 and 410−299 = 110 — exactly the menu's own position, matching the reporter's measurement, and 1274 is the reported scroll overflow. So on today's main the placement works only because no containing-block creator is present; the isolation is accidental. Portaling the child (measured the same way) restores 448/299-style placement and scrollWidth === clientWidth even with the declaration applied.

Change

  • Portal the child panel to the body (portalToBody, the same helper the root menu already uses from Sidebar.tsx). position: fixed, z-index, ids and aria-controls are unchanged, so nothing about the visual contract moves.
  • Pointer travel across the two halves: the child gets its own onPointerLeave that closes only when the pointer left both panels, and the root menu's leave check also accepts the portaled child. React's synthetic leave already follows the React tree through portals (verified in a React 19 + Chromium probe: moving onto the child fires no root leave), so these guards cover native leave sources rather than replacing React's behavior.
  • Follow the trigger: the repositioning effect now also observes the root menu's size and its scroll event, so the child keeps up when the menu grows asynchronously or is scrolled — today it only reacted to its own size and window resizes.

Keyboard behavior is untouched: React events still bubble from the portaled rows to the root menu's onKeyDown, closest('[role="menu"]') still identifies the child panel, and focus restore still finds the trigger inside the root menu.

Verification

  • test/sidebar-menu-panel.test.mjs — 9/9 pass; three new contracts pin the portal, the leave guards on both sides, and the scroll/size following.
  • test/worktree-menu-user-path.test.mjs (Electron user path) — updated to query the portaled child from document, plus two new steps: moving onto the child keeps it open, leaving both panels closes it. Fixture syntax-checked locally; the Electron run itself is the CI job's (this box has no Electron binary).
  • All test/sidebar*.test.mjs — 115/115 pass. tsc --noEmit clean.

One commit on main (541471d).

The child panel rendered inside the fixed, scrollable root menu, so it was only viewport-anchored while nothing on that menu created a containing block. With one present (the reporter's build carries backdrop-filter: blur(22px) saturate(1.55)) Chromium offsets the child by the menu's own position and the menu's scrollWidth jumps from 194 to 1274, which is the reported flying panel plus horizontal scrollbar. Measured directly in Chromium: plain CSS puts the child at the expected (448,299) with no overflow; adding the reported declaration moves it to (1980,410) — exactly the menu offset (900,110). Portal the panel to the body so no ancestor of the menu can offset it, add the pointer-leave guards for the two halves of the portal, and follow the trigger through root-menu scroll and growth.

vastsa commented Oct 26, 2026

Copy link
Copy Markdown
Owner

Independently reproduced this with the real SidebarMenuPanel in isolated Chromium and a backdrop-filter containing block. Old main reports an offset submenu and root scrollWidth 188 versus clientWidth 180; the candidate portals it outside, aligns panelLeft with triggerRight (280), and keeps scrollWidth/clientWidth at 180/180. Child actions still execute. All 10 focused contracts/real Electron worktree-menu journey tests pass, including pointer travel, click and keyboard navigation; Desktop typecheck passes. This repairs the existing placement contract without a design change. Refreshing the PR against current main and proceeding to merge, ignoring CI status as requested.

@vastsa
vastsa merged commit 520b9cb into vastsa:main Oct 26, 2026
6 checks passed

This branch was previously deployed

1 inactive deployment
Preview — 21799bad Deployed Oct 26, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants