Skip to content

Commit 01b2fde

Browse files
author
Alireza Mirian
committed
fix(overlays): fix an edge case in hiding outside elements
When working with WYSIWYG editors or similar components that mutate the dom, the order or dome mutations could be in a way that dom mutation observer is called for elements that are not yet appended to the modal dom at the time MutationObserver callback is called. This change adds a safe-guard for such cases, by checking if the target element is connected, as otherwise it will be considered outside the currently visible elements.
1 parent 4c91299 commit 01b2fde

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

packages/@react-aria/overlays/src/ariaHideOutside.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,12 @@ export function ariaHideOutside(targets: Element[], options?: AriaHideOutsideOpt
147147

148148
// If the parent element of the added nodes is not within one of the targets,
149149
// and not already inside a hidden node, hide all of the new children.
150-
if (![...visibleNodes, ...hiddenNodes].some(node => node.contains(change.target))) {
150+
if (
151+
change.target.isConnected &&
152+
![...visibleNodes, ...hiddenNodes].some((node) =>
153+
node.contains(change.target)
154+
)
155+
) {
151156
for (let node of change.addedNodes) {
152157
if (
153158
(node instanceof HTMLElement || node instanceof SVGElement) &&

0 commit comments

Comments
 (0)