Skip to content

Commit 475880d

Browse files
committed
Don't shadow global document/window, and fall back on them.
1 parent aec5c25 commit 475880d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ type AnyPortalNode<C extends Component<any> = Component<any>> = HtmlPortalNode<C
4444

4545

4646
const validateElementType = (domElement: Element, elementType: ANY_ELEMENT_TYPE) => {
47-
const document = domElement.ownerDocument as any;
47+
const ownerDocument = (domElement.ownerDocument ?? document) as any;
4848
// Cast document to `any` because Typescript doesn't know about the legacy `Document.parentWindow` field, and also
4949
// doesn't believe `Window.HTMLElement`/`Window.SVGElement` can be used in instanceof tests.
50-
const window = document.defaultView ?? document.parentWindow; // Fallback on `parentWindow` in order to support IE8 and earlier
50+
const ownerWindow = ownerDocument.defaultView ?? ownerDocument.parentWindow ?? window; // `parentWindow` for IE8 and earlier
5151
if (elementType === ELEMENT_TYPE_HTML) {
52-
return domElement instanceof window.HTMLElement;
52+
return domElement instanceof ownerWindow.HTMLElement;
5353
}
5454
if (elementType === ELEMENT_TYPE_SVG) {
55-
return domElement instanceof window.SVGElement;
55+
return domElement instanceof ownerWindow.SVGElement;
5656
}
5757
throw new Error(`Unrecognized element type "${elementType}" for validateElementType.`);
5858
};

0 commit comments

Comments
 (0)