@@ -167,9 +167,7 @@ let lastCurrentDocument: ?Document = null;
167
167
168
168
let previousDispatcher = null ;
169
169
export 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 ) ;
173
171
lastCurrentDocument = getDocumentFromRoot ( rootNode ) ;
174
172
175
173
previousDispatcher = Dispatcher . current ;
@@ -191,10 +189,20 @@ export type FloatRoot = Document | ShadowRoot;
191
189
// global maps of Resources
192
190
const preloadResources : Map < string , PreloadResource > = new Map ( ) ;
193
191
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
+
194
202
function getCurrentResourceRoot ( ) : null | FloatRoot {
195
203
const currentContainer = getCurrentRootHostContainer ( ) ;
196
204
// $FlowFixMe flow should know currentContainer is a Node and has getRootNode
197
- return currentContainer ? currentContainer . getRootNode ( ) : null ;
205
+ return currentContainer ? getRootNode ( currentContainer ) : null ;
198
206
}
199
207
200
208
// This resource type constraint can be loosened. It really is everything except PreloadResource
@@ -204,7 +212,7 @@ function resetInstance(resource: ScriptResource | HeadResource) {
204
212
}
205
213
206
214
export function clearRootResources ( rootContainer : Container ) : void {
207
- const rootNode : FloatRoot = ( rootContainer . getRootNode ( ) : any ) ;
215
+ const rootNode = getRootNode ( rootContainer ) ;
208
216
const resources = getResourcesFromRoot ( rootNode ) ;
209
217
210
218
// We can't actually delete the resource cache because this function is called
0 commit comments