From a26d25c0e07790317619b2bf5d8b185708db9e24 Mon Sep 17 00:00:00 2001 From: Devon Govett Date: Mon, 12 May 2025 10:29:57 -0700 Subject: [PATCH 1/2] Check for moveBefore on instance instead of prototype --- .../src/client/ReactFiberConfigDOM.js | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js b/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js index 5aa26b26340d5..d6697d7aa0a33 100644 --- a/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js +++ b/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js @@ -932,18 +932,12 @@ 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 +997,8 @@ 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 +1009,8 @@ 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 +1039,8 @@ 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 +1068,8 @@ 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); From dcc1f192f9bf4f199f74c906dd657e2105def2b1 Mon Sep 17 00:00:00 2001 From: Devon Govett Date: Mon, 12 May 2025 10:39:00 -0700 Subject: [PATCH 2/2] prettier --- .../src/client/ReactFiberConfigDOM.js | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js b/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js index d6697d7aa0a33..88c54231defdc 100644 --- a/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js +++ b/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js @@ -936,7 +936,11 @@ export function appendChild( parentInstance: Instance, child: Instance | TextInstance, ): void { - if (enableMoveBefore && typeof (parentInstance: any).moveBefore === 'function' && child.parentNode !== null) { + if ( + enableMoveBefore && + typeof (parentInstance: any).moveBefore === 'function' && + child.parentNode !== null + ) { // $FlowFixMe[prop-missing]: We've checked this above. parentInstance.moveBefore(child, null); } else { @@ -997,7 +1001,11 @@ export function appendChildToContainer( container.nodeType === COMMENT_NODE ) { parentNode = (container.parentNode: any); - if (enableMoveBefore && typeof parentNode.moveBefore === 'function' && child.parentNode !== null) { + if ( + enableMoveBefore && + typeof parentNode.moveBefore === 'function' && + child.parentNode !== null + ) { // $FlowFixMe[prop-missing]: We've checked this above. parentNode.moveBefore(child, container); } else { @@ -1009,7 +1017,11 @@ export function appendChildToContainer( } else { parentNode = (container: any); } - if (enableMoveBefore && typeof parentNode.moveBefore === 'function' && child.parentNode !== null) { + if ( + enableMoveBefore && + typeof parentNode.moveBefore === 'function' && + child.parentNode !== null + ) { // $FlowFixMe[prop-missing]: We've checked this above. parentNode.moveBefore(child, null); } else { @@ -1039,7 +1051,11 @@ export function insertBefore( child: Instance | TextInstance, beforeChild: Instance | TextInstance | SuspenseInstance | ActivityInstance, ): void { - if (enableMoveBefore && typeof (parentInstance: any).moveBefore === 'function' && child.parentNode !== null) { + if ( + enableMoveBefore && + typeof (parentInstance: any).moveBefore === 'function' && + child.parentNode !== null + ) { // $FlowFixMe[prop-missing]: We've checked this above. parentInstance.moveBefore(child, beforeChild); } else { @@ -1068,7 +1084,11 @@ export function insertInContainerBefore( } else { parentNode = (container: any); } - if (enableMoveBefore && typeof parentNode.moveBefore === 'function' && child.parentNode !== null) { + if ( + enableMoveBefore && + typeof parentNode.moveBefore === 'function' && + child.parentNode !== null + ) { // $FlowFixMe[prop-missing]: We've checked this above. parentNode.moveBefore(child, beforeChild); } else {