Skip to content

Commit b48e739

Browse files
authored
[Fiber] getHoistableRoot() should account for Document containers (facebook#32321)
While modern DOM implementations all support getRootNode if you are running React in a runtime which does not the fallback logic which uses `.ownerDocument` works everywhere except when the container is a Document itself. This change corrects this by returning the container intsance if it is a Document type.
1 parent ff62833 commit b48e739

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -2523,10 +2523,13 @@ export type HoistableRoot = Document | ShadowRoot;
25232523
export function getHoistableRoot(container: Container): HoistableRoot {
25242524
// $FlowFixMe[method-unbinding]
25252525
return typeof container.getRootNode === 'function'
2526-
? /* $FlowFixMe[incompatible-return] Flow types this as returning a `Node`,
2526+
? /* $FlowFixMe[incompatible-cast] Flow types this as returning a `Node`,
25272527
* but it's either a `Document` or `ShadowRoot`. */
2528-
container.getRootNode()
2529-
: container.ownerDocument;
2528+
(container.getRootNode(): Document | ShadowRoot)
2529+
: container.nodeType === DOCUMENT_NODE
2530+
? // $FlowFixMe[incompatible-cast] We've constrained this to be a Document which satisfies the return type
2531+
(container: Document)
2532+
: container.ownerDocument;
25302533
}
25312534

25322535
function getCurrentResourceRoot(): null | HoistableRoot {

0 commit comments

Comments
 (0)