diff --git a/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js b/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js index 5aa26b26340d5..88c54231defdc 100644 --- a/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js +++ b/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js @@ -932,18 +932,16 @@ export function commitTextUpdate( textInstance.nodeValue = newText; } -const supportsMoveBefore = - // $FlowFixMe[prop-missing]: We're doing the feature detection here. - enableMoveBefore && - typeof window !== 'undefined' && - typeof window.Element.prototype.moveBefore === 'function'; - export function appendChild( parentInstance: Instance, child: Instance | TextInstance, ): void { - if (supportsMoveBefore && child.parentNode !== null) { - // $FlowFixMe[prop-missing]: We've checked this with supportsMoveBefore. + if ( + enableMoveBefore && + typeof (parentInstance: any).moveBefore === 'function' && + child.parentNode !== null + ) { + // $FlowFixMe[prop-missing]: We've checked this above. parentInstance.moveBefore(child, null); } else { parentInstance.appendChild(child); @@ -1003,8 +1001,12 @@ export function appendChildToContainer( container.nodeType === COMMENT_NODE ) { parentNode = (container.parentNode: any); - if (supportsMoveBefore && child.parentNode !== null) { - // $FlowFixMe[prop-missing]: We've checked this with supportsMoveBefore. + if ( + enableMoveBefore && + typeof parentNode.moveBefore === 'function' && + child.parentNode !== null + ) { + // $FlowFixMe[prop-missing]: We've checked this above. parentNode.moveBefore(child, container); } else { parentNode.insertBefore(child, container); @@ -1015,8 +1017,12 @@ export function appendChildToContainer( } else { parentNode = (container: any); } - if (supportsMoveBefore && child.parentNode !== null) { - // $FlowFixMe[prop-missing]: We've checked this with supportsMoveBefore. + if ( + enableMoveBefore && + typeof parentNode.moveBefore === 'function' && + child.parentNode !== null + ) { + // $FlowFixMe[prop-missing]: We've checked this above. parentNode.moveBefore(child, null); } else { parentNode.appendChild(child); @@ -1045,8 +1051,12 @@ export function insertBefore( child: Instance | TextInstance, beforeChild: Instance | TextInstance | SuspenseInstance | ActivityInstance, ): void { - if (supportsMoveBefore && child.parentNode !== null) { - // $FlowFixMe[prop-missing]: We've checked this with supportsMoveBefore. + if ( + enableMoveBefore && + typeof (parentInstance: any).moveBefore === 'function' && + child.parentNode !== null + ) { + // $FlowFixMe[prop-missing]: We've checked this above. parentInstance.moveBefore(child, beforeChild); } else { parentInstance.insertBefore(child, beforeChild); @@ -1074,8 +1084,12 @@ export function insertInContainerBefore( } else { parentNode = (container: any); } - if (supportsMoveBefore && child.parentNode !== null) { - // $FlowFixMe[prop-missing]: We've checked this with supportsMoveBefore. + if ( + enableMoveBefore && + typeof parentNode.moveBefore === 'function' && + child.parentNode !== null + ) { + // $FlowFixMe[prop-missing]: We've checked this above. parentNode.moveBefore(child, beforeChild); } else { parentNode.insertBefore(child, beforeChild);