@@ -167,9 +167,7 @@ let lastCurrentDocument: ?Document = null;
167167
168168let previousDispatcher = null ;
169169export function prepareToRenderResources ( rootContainer : Container ) {
170- // Flot thinks that getRootNode returns a Node but it actually returns a
171- // Document or ShadowRoot
172- const rootNode : FloatRoot = ( rootContainer . getRootNode ( ) : any ) ;
170+ const rootNode = getRootNode ( rootContainer ) ;
173171 lastCurrentDocument = getDocumentFromRoot ( rootNode ) ;
174172
175173 previousDispatcher = Dispatcher . current ;
@@ -191,10 +189,20 @@ export type FloatRoot = Document | ShadowRoot;
191189// global maps of Resources
192190const preloadResources : Map < string , PreloadResource > = new Map ( ) ;
193191
192+ // getRootNode is missing from IE and old jsdom versions
193+ function getRootNode ( container : Container ) : FloatRoot {
194+ // $FlowFixMe[method-unbinding]
195+ return typeof container . getRootNode === 'function'
196+ ? /* $FlowFixMe[incompatible-return] Flow types this as returning a `Node`,
197+ * but it's either a `Document` or `ShadowRoot`. */
198+ container . getRootNode ( )
199+ : container . ownerDocument ;
200+ }
201+
194202function getCurrentResourceRoot ( ) : null | FloatRoot {
195203 const currentContainer = getCurrentRootHostContainer ( ) ;
196204 // $FlowFixMe flow should know currentContainer is a Node and has getRootNode
197- return currentContainer ? currentContainer . getRootNode ( ) : null ;
205+ return currentContainer ? getRootNode ( currentContainer ) : null ;
198206}
199207
200208// This resource type constraint can be loosened. It really is everything except PreloadResource
@@ -204,7 +212,7 @@ function resetInstance(resource: ScriptResource | HeadResource) {
204212}
205213
206214export function clearRootResources ( rootContainer : Container ) : void {
207- const rootNode : FloatRoot = ( rootContainer . getRootNode ( ) : any ) ;
215+ const rootNode = getRootNode ( rootContainer ) ;
208216 const resources = getResourcesFromRoot ( rootNode ) ;
209217
210218 // We can't actually delete the resource cache because this function is called
0 commit comments