Skip to content

Commit aec5c25

Browse files
committed
Support reverse portals in iframes and other windows.
1 parent e269286 commit aec5c25

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/index.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +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;
48+
// Cast document to `any` because Typescript doesn't know about the legacy `Document.parentWindow` field, and also
49+
// 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
4751
if (elementType === ELEMENT_TYPE_HTML) {
48-
return domElement instanceof HTMLElement;
52+
return domElement instanceof window.HTMLElement;
4953
}
5054
if (elementType === ELEMENT_TYPE_SVG) {
51-
return domElement instanceof SVGElement;
55+
return domElement instanceof window.SVGElement;
5256
}
5357
throw new Error(`Unrecognized element type "${elementType}" for validateElementType.`);
5458
};

0 commit comments

Comments
 (0)