Skip to content

[popups] Fix outside press dismissal in shared shadow root#4333

Merged
atomiks merged 3 commits intomui:masterfrom
atomiks:codex/fix-shadow-root-outside-press
Mar 13, 2026
Merged

[popups] Fix outside press dismissal in shared shadow root#4333
atomiks merged 3 commits intomui:masterfrom
atomiks:codex/fix-shadow-root-outside-press

Conversation

@atomiks
Copy link
Contributor

@atomiks atomiks commented Mar 13, 2026

Fixes #4332

Summary

This fixes outside press dismissal for popups rendered inside a shared ShadowRoot.

The old logic in useDismiss collected data-base-ui-inert markers from the owner document, and the previous shadow DOM follow-up also appended markers from the target's shadow root. That left the injected-element guard comparing a mixed set of markers from different roots.

For clicks on ordinary sibling elements inside the same ShadowRoot, the target's ancestor chain did not contain the document-level markers, so the click could still be treated as a third-party injected element and ignored. The new logic scopes the marker lookup to the event target's actual root, so same-shadow-root outside clicks are compared against the correct marker set and dismiss normally.

Changes

  • Scope the inert marker lookup in useDismiss to the event target's actual root instead of mixing document-level and shadow-root markers.
  • Add a regression test that mounts the app inside a ShadowRoot, portals the dialog into that root, and verifies clicking a sibling element dismisses it.

@atomiks atomiks added type: bug It doesn't behave as expected. scope: all components Widespread work has an impact on almost all components. labels Mar 13, 2026
@atomiks
Copy link
Contributor Author

atomiks commented Mar 13, 2026

Codex Review

Overview

This change fixes outside press dismissal for popups that are mounted and portaled within the same shadow root. It narrows the inert-marker lookup to the event target's actual root and now covers the shadow-root behavior at the hook level plus dialog and popover integration points.

Findings (None)

No blocking issues found in this patch.

Confidence: 4/5

High confidence based on a full pass over the branch diff, the shared useDismiss code path, and focused regression coverage for same-root clicks, outside-the-root clicks, modal dialog behavior, and non-modal popover behavior.

Notes

  • Reviewed the branch against master, including correctness, accessibility, API/state, maintainability, performance risk, and test coverage.
  • Verified with focused useDismiss, DialogRoot, and PopoverRoot runs in JSDOM and Chromium.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 13, 2026

commit: e69c0d6

@mui-bot
Copy link

mui-bot commented Mar 13, 2026

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react ▼-64B(-0.01%) ▼-15B(-0.01%)

Details of bundle changes


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

@atomiks atomiks force-pushed the codex/fix-shadow-root-outside-press branch from 3b9793d to 0a9f401 Compare March 13, 2026 10:55
@netlify
Copy link

netlify bot commented Mar 13, 2026

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 3b9793d
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/69b3ec9fe187fd00087a1773
😎 Deploy Preview https://deploy-preview-4333--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@netlify
Copy link

netlify bot commented Mar 13, 2026

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit e69c0d6
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/69b3f4e541b4ca000747a2d0
😎 Deploy Preview https://deploy-preview-4333--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@atomiks atomiks marked this pull request as ready for review March 13, 2026 11:00
@atomiks atomiks merged commit e486c5c into mui:master Mar 13, 2026
23 checks passed
@atomiks atomiks deleted the codex/fix-shadow-root-outside-press branch March 13, 2026 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: all components Widespread work has an impact on almost all components. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ShadowDOM: Popup don't dismiss when clicking other elements inside the same ShadowRoot

2 participants