Skip to content

Commit e69ca31

Browse files
authored
Revert "Refactor commitPlacement to recursively insert nodes (#17996)" (#18517)
This reverts commit df5fadd.
1 parent 3278d24 commit e69ca31

File tree

1 file changed

+33
-61
lines changed

1 file changed

+33
-61
lines changed

packages/react-reconciler/src/ReactFiberCommitWork.js

Lines changed: 33 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,72 +1283,44 @@ function commitPlacement(finishedWork: Fiber): void {
12831283
const before = getHostSibling(finishedWork);
12841284
// We only have the top Fiber that was inserted but we need to recurse down its
12851285
// children to find all the terminal nodes.
1286-
if (isContainer) {
1287-
insertOrAppendPlacementNodeIntoContainer(finishedWork, before, parent);
1288-
} else {
1289-
insertOrAppendPlacementNode(finishedWork, before, parent);
1290-
}
1291-
}
1292-
1293-
function insertOrAppendPlacementNodeIntoContainer(
1294-
node: Fiber,
1295-
before: ?Instance,
1296-
parent: Container,
1297-
): void {
1298-
const {tag} = node;
1299-
const isHost = tag === HostComponent || tag === HostText;
1300-
if (isHost || (enableFundamentalAPI && tag === FundamentalComponent)) {
1301-
const stateNode = isHost ? node.stateNode : node.stateNode.instance;
1302-
if (before) {
1303-
insertInContainerBefore(parent, stateNode, before);
1304-
} else {
1305-
appendChildToContainer(parent, stateNode);
1306-
}
1307-
} else if (tag === HostPortal) {
1308-
// If the insertion itself is a portal, then we don't want to traverse
1309-
// down its children. Instead, we'll get insertions from each child in
1310-
// the portal directly.
1311-
} else {
1312-
const child = node.child;
1313-
if (child !== null) {
1314-
insertOrAppendPlacementNodeIntoContainer(child, before, parent);
1315-
let sibling = child.sibling;
1316-
while (sibling !== null) {
1317-
insertOrAppendPlacementNodeIntoContainer(sibling, before, parent);
1318-
sibling = sibling.sibling;
1286+
let node: Fiber = finishedWork;
1287+
while (true) {
1288+
const isHost = node.tag === HostComponent || node.tag === HostText;
1289+
if (isHost || (enableFundamentalAPI && node.tag === FundamentalComponent)) {
1290+
const stateNode = isHost ? node.stateNode : node.stateNode.instance;
1291+
if (before) {
1292+
if (isContainer) {
1293+
insertInContainerBefore(parent, stateNode, before);
1294+
} else {
1295+
insertBefore(parent, stateNode, before);
1296+
}
1297+
} else {
1298+
if (isContainer) {
1299+
appendChildToContainer(parent, stateNode);
1300+
} else {
1301+
appendChild(parent, stateNode);
1302+
}
13191303
}
1304+
} else if (node.tag === HostPortal) {
1305+
// If the insertion itself is a portal, then we don't want to traverse
1306+
// down its children. Instead, we'll get insertions from each child in
1307+
// the portal directly.
1308+
} else if (node.child !== null) {
1309+
node.child.return = node;
1310+
node = node.child;
1311+
continue;
13201312
}
1321-
}
1322-
}
1323-
1324-
function insertOrAppendPlacementNode(
1325-
node: Fiber,
1326-
before: ?Instance,
1327-
parent: Instance,
1328-
): void {
1329-
const {tag} = node;
1330-
const isHost = tag === HostComponent || tag === HostText;
1331-
if (isHost || (enableFundamentalAPI && tag === FundamentalComponent)) {
1332-
const stateNode = isHost ? node.stateNode : node.stateNode.instance;
1333-
if (before) {
1334-
insertBefore(parent, stateNode, before);
1335-
} else {
1336-
appendChild(parent, stateNode);
1313+
if (node === finishedWork) {
1314+
return;
13371315
}
1338-
} else if (tag === HostPortal) {
1339-
// If the insertion itself is a portal, then we don't want to traverse
1340-
// down its children. Instead, we'll get insertions from each child in
1341-
// the portal directly.
1342-
} else {
1343-
const child = node.child;
1344-
if (child !== null) {
1345-
insertOrAppendPlacementNode(child, before, parent);
1346-
let sibling = child.sibling;
1347-
while (sibling !== null) {
1348-
insertOrAppendPlacementNode(sibling, before, parent);
1349-
sibling = sibling.sibling;
1316+
while (node.sibling === null) {
1317+
if (node.return === null || node.return === finishedWork) {
1318+
return;
13501319
}
1320+
node = node.return;
13511321
}
1322+
node.sibling.return = node.return;
1323+
node = node.sibling;
13521324
}
13531325
}
13541326

0 commit comments

Comments
 (0)