Fix outside click detection when component is mounted in the Shadow DOM #2866
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If a component (like a
<Popover>
) was mounted inside the Shadow DOM we wouldn't handle outside clicks correctly. Our outside click handling has to detect "3rd-party" elements in the DOM to make sure interacting with things like Grammarly still work. In Next.js the app is wrapped in a div (in non RSC situations) and, when a component was mounted inside the Shadow DOM, we'd detect this wrapping element as a valid 3rd-party element.This PR fixes this my detecting if the component is mounted inside the shadow DOM, and if so, looking for the corresponding host element instead of the hidden node element we normally use.
Fixes #2856