File tree 1 file changed +6
-2
lines changed
1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -44,11 +44,15 @@ type AnyPortalNode<C extends Component<any> = Component<any>> = HtmlPortalNode<C
44
44
45
45
46
46
const validateElementType = ( domElement : Element , elementType : ANY_ELEMENT_TYPE ) => {
47
+ const ownerDocument = ( domElement . ownerDocument ?? document ) 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 ownerWindow = ownerDocument . defaultView ?? ownerDocument . parentWindow ?? window ; // `parentWindow` for IE8 and earlier
47
51
if ( elementType === ELEMENT_TYPE_HTML ) {
48
- return domElement instanceof HTMLElement ;
52
+ return domElement instanceof ownerWindow . HTMLElement ;
49
53
}
50
54
if ( elementType === ELEMENT_TYPE_SVG ) {
51
- return domElement instanceof SVGElement ;
55
+ return domElement instanceof ownerWindow . SVGElement ;
52
56
}
53
57
throw new Error ( `Unrecognized element type "${ elementType } " for validateElementType.` ) ;
54
58
} ;
You can’t perform that action at this time.
0 commit comments