Skip to content

Conversation

johnpangalos
Copy link

Closes #8675

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

Not sure what the test instructions would be, I have this reproduction repo: https://github.com/johnpangalos/rac-shadow-dom-bug-report, but some of the React Spectrum team couldn't run it. I can try and set it up so that you can link the repo to a build of RAC.

I have one non passing test, but I thought it was best to put up a PR anyway with the changes I've had time to finish so far.

The tests were originally created by AI, but I've had to alter them to get them to test what I'd actually like them to test.

🧢 Your Project:

Thomson Reuters (Pagero)

johnpangalos and others added 7 commits August 7, 2025 11:46
These tests specifically target issue adobe#8675 where menu items in
popovers close immediately instead when using ShadowDOM with
UNSAFE_PortalProvider.

New test suites added:
- FocusScope: Shadow DOM boundary containment issues
- usePopover: Shadow DOM popover interactions and focus management
- useFocusWithin: Focus within detection across shadow boundaries
- useInteractOutside: Interact outside detection with portals

I generated these tests with AI then reviewed / updated them.
After applying the patches I mentioned in my issue I've noticed that
many of the AI generated tests were either broken or just not testing
anything interesting. Luckily there are some that are.

I'll have to update the rest of the tests as they aren't passing at the
moment.
I have a conflicting default prettier config (I can't seem to find this
projects.) I'm reverting a number of my autochanges.
There are a bunch of redundant tests. Getting rid of them for now.
Copy link
Member

@snowystinger snowystinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pushing this up, it really helps!!
A few starter comments, but I really really appreciate the start on the tests

*/
export function getEventTarget<T extends Event>(event: T): Element {
if (shadowDOM() && (event.target as HTMLElement).shadowRoot) {
if (shadowDOM() && (event.target as HTMLElement)?.shadowRoot) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting, when was this not defined?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a while ago I did this, I'll try and reproduce it and see exactly when this happened.

I added a popover test but it seems that when creating my replication in
test code I noticed that the popover is never displayed. Seems that there
is an issue with showing popovers in the tests when everything is in the
shadow dom...
I had to add another dependency to get the test to actually find the
parts of the shadow dom I was interested in. Seems like the default
testing libraries don't cover this case unfortunately.
@johnpangalos
Copy link
Author

Okay so I've updated this to have a much better test which in my opinion tests the functionality. I unfortunately had to add another dependency to do so: https://github.com/konnorrogers/shadow-dom-testing-library

I wasn't able to find the shadow dom elements without it 🤷

The bad news is that I reverted the code changes and the test still passes so I'm not sure what's going on. Either:

  • I didn't represent what I want in the test -OR-
  • The jsdom implementation is making it work in both cases.

Either way this is a more complete PR at least.

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.

RAC Menu not able to click menu items when using UNSAFE_PortalProvider in a web component

2 participants