Skip to content

[Dialog & AlertDialog] fix: can't get id correctly in shadow dom#3384

Open
molvqingtai wants to merge 2 commits intoradix-ui:mainfrom
molvqingtai:bugfix
Open

[Dialog & AlertDialog] fix: can't get id correctly in shadow dom#3384
molvqingtai wants to merge 2 commits intoradix-ui:mainfrom
molvqingtai:bugfix

Conversation

@molvqingtai
Copy link

@molvqingtai molvqingtai commented Feb 16, 2025

Description

Using document.getElementById in Shadow DOM contexts will fail to access encapsulated elements. The correct approach is to query the element by ID from the parent DialogContent container instead.

fixed #3484
#2986 (comment)

@dylnslck
Copy link

Getting this merged in would be amazing.

@peguimasid
Copy link

This PR would be extremely helpful! I'm rendering my dialogs in a Shadow DOM for style isolation and getting these exact console errors since the components can't find elements across Shadow DOM boundaries.

@aleksolutions
Copy link

Hi! 👋

Thank you so much for working on this PR!

I encountered this exact issue while developing a browser extension where rendering AlertDialogContent inside a Shadow DOM (using Portal container={shadowRoot}) is necessary for style isolation. This setup causes the TitleWarning check (document.getElementById) to fail, resulting in a false positive console.error because the check doesn't search within the specified container.

This PR seems to address the problem perfectly by making the accessibility check container-aware.

I've tested the changes locally by applying this PR's code using pnpm patch, and I can confirm that it successfully resolves the console error in my Shadow DOM scenario without any apparent side effects. The dialog remains accessible and functional.

This fix is a great improvement for developers working with Radix primitives in environments like browser extensions or micro-frontends that rely on Shadow DOM.

Looking forward to seeing this merged! Thanks again!

@spencermarx
Copy link

spencermarx commented May 4, 2025

Nice work on the MR, would love to see this merge in so we can upgrade and no longer see these console.errors 🙏

@nicogave
Copy link

Also having the issue when integrating the Dialog in Shadow Dom, can't wait for this fix to be merged !

Cheers !

@plawgp
Copy link

plawgp commented Aug 22, 2025

Also have the same implementation using Shadow DOM, and seeing the same errors.

Would love to see this merged so our logs aren't polluted! @chaance

@stevencjyu
Copy link

stevencjyu commented Oct 8, 2025

We're running into exactly the same error in our app when rendering dialogs in shadow roots. Really hoping this can land. Is there anything we can help?

@changeset-bot
Copy link

changeset-bot bot commented Jan 19, 2026

⚠️ No Changeset found

Latest commit: 0c5fe69

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@radix-ui/react-dialog: Accessibility error inside shadow dom

8 participants