@@ -93,6 +93,7 @@ import {
9393 enableTrustedTypesIntegration ,
9494 enableAsyncActions ,
9595 disableLegacyMode ,
96+ enableMoveBefore ,
9697} from 'shared/ReactFeatureFlags' ;
9798import {
9899 HostComponent ,
@@ -525,6 +526,7 @@ export function appendInitialChild(
525526 parentInstance : Instance ,
526527 child : Instance | TextInstance ,
527528) : void {
529+ // Note: This should not use moveBefore() because initial are appended while disconnected.
528530 parentInstance . appendChild ( child ) ;
529531}
530532
@@ -761,7 +763,12 @@ export function appendChild(
761763 parentInstance : Instance ,
762764 child : Instance | TextInstance ,
763765) : void {
764- parentInstance . appendChild ( child ) ;
766+ if ( supportsMoveBefore ) {
767+ // $FlowFixMe[prop-missing]: We've checked this with supportsMoveBefore.
768+ parentInstance . moveBefore ( child , null ) ;
769+ } else {
770+ parentInstance . appendChild ( child ) ;
771+ }
765772}
766773
767774export function appendChildToContainer (
@@ -794,12 +801,21 @@ export function appendChildToContainer(
794801 }
795802}
796803
804+ const supportsMoveBefore =
805+ // $FlowFixMe[prop-missing]: We're doing the feature detection here.
806+ enableMoveBefore && typeof Node . prototype . moveBefore === 'function' ;
807+
797808export function insertBefore (
798809 parentInstance : Instance ,
799810 child : Instance | TextInstance ,
800811 beforeChild : Instance | TextInstance | SuspenseInstance ,
801812) : void {
802- parentInstance. insertBefore ( child , beforeChild ) ;
813+ if ( supportsMoveBefore ) {
814+ // $FlowFixMe[prop-missing]: We've checked this with supportsMoveBefore.
815+ parentInstance . moveBefore ( child , beforeChild ) ;
816+ } else {
817+ parentInstance . insertBefore ( child , beforeChild ) ;
818+ }
803819}
804820
805821export function insertInContainerBefore (
0 commit comments