Skip to content

[dialog] Keep parent open when closing a nested dialog in a closed shadow root - #5780

Merged
atomiks merged 3 commits into
mui:masterfrom
atomiks:claude/dialog-closed-shadow-root-5650
Sep 24, 2026
Merged

atomiks merged 3 commits into
mui:masterfrom
atomiks:claude/dialog-closed-shadow-root-5650

Conversation

@atomiks

@atomiks atomiks commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #5650

When a dialog is portaled into a closed shadow root, clicking inside a nested dialog (for example its Dialog.Close) also dismissed the parent dialog with reason outside-press.

From the document, a closed shadow root hides the real target: composedPath() stops at the shadow host, so the parent's useDismiss can't tell that the press landed inside its popup tree. The only signal left is the React-tree marker (insideReactTree), which the popup's capture handlers set before the press reaches the host. But with real input, React flushes the nested dialog's close in a microtask before the host listener runs. That flips the parent's escapeKey/topmost state and re-runs its dismiss effect, and the effect's cleanup cleared the marker. The press was then treated as outside.

This PR stops clearing the marker in that effect's cleanup and clears it on unmount instead. The existing 0 ms timeout and the reset on reopen still clear it as before. Open shadow roots and light DOM aren't affected, since there the target check runs before React handles the press.

Nested Dialog (modal and non-modal) and AlertDialog inside a Dialog were affected whenever either popup was portaled into the closed shadow root. Popover, Menu, and Select inside a dialog, and nested popovers, already worked because closing them doesn't change the parent's dismiss effect.

The tests cover each nested kind across the possible portal setups (outer and nested in the shadow root, the body, or the inherited default). Synthetic clicks and act() both defer React's flush until after the host listener, which hides the bug, so the test click flushes React from a shadow root listener, which is what the browser's microtask checkpoint does for trusted input.

@atomiks atomiks added type: bug It doesn't behave as expected. component: dialog Changes related to the dialog component. labels Sep 23, 2026
@pkg-pr-new

pkg-pr-new Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@5780
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@5780
    

commit: 6ee8bf9

@code-infra-dashboard

code-infra-dashboard Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+19B(0.00%) 🔺+4B(0.00%)

Details of bundle changes

Performance

Total duration: 1,045.38 ms -111.75 ms(-9.7%) | Renders: 76 (+0) | Paint: 1,706.31 ms -206.55 ms(-10.8%)

Test Duration Renders
Checkbox mount (500 instances) 107.20 ms 🔺+37.82 ms(+54.5%) 1 (+0)
Mixed surface mount (app-like density) 67.15 ms ▼-19.73 ms(-22.7%) 5 (+0)
Select open (500 options) 61.37 ms ▼-19.61 ms(-24.2%) 14 (+0)
Combobox type — 500 items, narrows to ~11 (type "Row 25") 26.57 ms ▼-11.33 ms(-29.9%) 15 (+0)
Combobox type — 500 items, all stay mounted (type "Row ") 23.41 ms ▼-9.87 ms(-29.7%) 11 (+0)

10 tests within noise — details

Metric alarms

Test Metric Change
Checkbox mount (500 instances) bench:paint 🔺 +41.11 ms

Check out the code infra dashboard for more information about this PR.

@netlify

netlify Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 6ee8bf9
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6ab4d1893bc6d5000875df74
😎 Deploy Preview https://deploy-preview-5780--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@atomiks
atomiks merged commit 0b417e8 into mui:master Sep 24, 2026
24 checks passed
@atomiks
atomiks deleted the claude/dialog-closed-shadow-root-5650 branch September 24, 2026 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: dialog Changes related to the dialog component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[dialog] Closing a nested Dialog dismisses its parent inside a closed shadow root

1 participant