Skip to content

Commit 3e62455

Browse files
committed
Use moveBefore if available and the flag is on
1 parent 8d3dbe2 commit 3e62455

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ import {
9393
enableTrustedTypesIntegration,
9494
enableAsyncActions,
9595
disableLegacyMode,
96+
enableMoveBefore,
9697
} from 'shared/ReactFeatureFlags';
9798
import {
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

767774
export 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+
797808
export 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

805821
export function insertInContainerBefore(

0 commit comments

Comments
 (0)