Skip to content

Commit

Permalink
[Fiber] getHoistableRoot() should account for Document containers (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
gnoff authored Feb 6, 2025
1 parent ff62833 commit b48e739
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -2523,10 +2523,13 @@ export type HoistableRoot = Document | ShadowRoot;
export function getHoistableRoot(container: Container): HoistableRoot {
// $FlowFixMe[method-unbinding]
return typeof container.getRootNode === 'function'
? /* $FlowFixMe[incompatible-return] Flow types this as returning a `Node`,
? /* $FlowFixMe[incompatible-cast] Flow types this as returning a `Node`,
* but it's either a `Document` or `ShadowRoot`. */
container.getRootNode()
: container.ownerDocument;
(container.getRootNode(): Document | ShadowRoot)
: container.nodeType === DOCUMENT_NODE
? // $FlowFixMe[incompatible-cast] We've constrained this to be a Document which satisfies the return type
(container: Document)
: container.ownerDocument;
}

function getCurrentResourceRoot(): null | HoistableRoot {
Expand Down

0 comments on commit b48e739

Please sign in to comment.