mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Avoid conditions where control flow is sufficient (#24126)
This also fixes a type error since resetTextContent can only be called on Instances.
This commit is contained in:
@@ -1567,22 +1567,29 @@ function commitPlacement(finishedWork: Fiber): void {
|
||||
const parentFiber = getHostParentFiber(finishedWork);
|
||||
|
||||
// Note: these two variables *must* always be updated together.
|
||||
let parent;
|
||||
let isContainer;
|
||||
const parentStateNode = parentFiber.stateNode;
|
||||
switch (parentFiber.tag) {
|
||||
case HostComponent:
|
||||
parent = parentStateNode;
|
||||
isContainer = false;
|
||||
case HostComponent: {
|
||||
const parent: Instance = parentFiber.stateNode;
|
||||
if (parentFiber.flags & ContentReset) {
|
||||
// Reset the text content of the parent before doing any insertions
|
||||
resetTextContent(parent);
|
||||
// Clear ContentReset from the effect tag
|
||||
parentFiber.flags &= ~ContentReset;
|
||||
}
|
||||
|
||||
const before = getHostSibling(finishedWork);
|
||||
// We only have the top Fiber that was inserted but we need to recurse down its
|
||||
// children to find all the terminal nodes.
|
||||
insertOrAppendPlacementNode(finishedWork, before, parent);
|
||||
break;
|
||||
}
|
||||
case HostRoot:
|
||||
parent = parentStateNode.containerInfo;
|
||||
isContainer = true;
|
||||
break;
|
||||
case HostPortal:
|
||||
parent = parentStateNode.containerInfo;
|
||||
isContainer = true;
|
||||
case HostPortal: {
|
||||
const parent: Container = parentFiber.stateNode.containerInfo;
|
||||
const before = getHostSibling(finishedWork);
|
||||
insertOrAppendPlacementNodeIntoContainer(finishedWork, before, parent);
|
||||
break;
|
||||
}
|
||||
// eslint-disable-next-line-no-fallthrough
|
||||
default:
|
||||
throw new Error(
|
||||
@@ -1590,21 +1597,6 @@ function commitPlacement(finishedWork: Fiber): void {
|
||||
'in React. Please file an issue.',
|
||||
);
|
||||
}
|
||||
if (parentFiber.flags & ContentReset) {
|
||||
// Reset the text content of the parent before doing any insertions
|
||||
resetTextContent(parent);
|
||||
// Clear ContentReset from the effect tag
|
||||
parentFiber.flags &= ~ContentReset;
|
||||
}
|
||||
|
||||
const before = getHostSibling(finishedWork);
|
||||
// We only have the top Fiber that was inserted but we need to recurse down its
|
||||
// children to find all the terminal nodes.
|
||||
if (isContainer) {
|
||||
insertOrAppendPlacementNodeIntoContainer(finishedWork, before, parent);
|
||||
} else {
|
||||
insertOrAppendPlacementNode(finishedWork, before, parent);
|
||||
}
|
||||
}
|
||||
|
||||
function insertOrAppendPlacementNodeIntoContainer(
|
||||
|
||||
@@ -1567,22 +1567,29 @@ function commitPlacement(finishedWork: Fiber): void {
|
||||
const parentFiber = getHostParentFiber(finishedWork);
|
||||
|
||||
// Note: these two variables *must* always be updated together.
|
||||
let parent;
|
||||
let isContainer;
|
||||
const parentStateNode = parentFiber.stateNode;
|
||||
switch (parentFiber.tag) {
|
||||
case HostComponent:
|
||||
parent = parentStateNode;
|
||||
isContainer = false;
|
||||
case HostComponent: {
|
||||
const parent: Instance = parentFiber.stateNode;
|
||||
if (parentFiber.flags & ContentReset) {
|
||||
// Reset the text content of the parent before doing any insertions
|
||||
resetTextContent(parent);
|
||||
// Clear ContentReset from the effect tag
|
||||
parentFiber.flags &= ~ContentReset;
|
||||
}
|
||||
|
||||
const before = getHostSibling(finishedWork);
|
||||
// We only have the top Fiber that was inserted but we need to recurse down its
|
||||
// children to find all the terminal nodes.
|
||||
insertOrAppendPlacementNode(finishedWork, before, parent);
|
||||
break;
|
||||
}
|
||||
case HostRoot:
|
||||
parent = parentStateNode.containerInfo;
|
||||
isContainer = true;
|
||||
break;
|
||||
case HostPortal:
|
||||
parent = parentStateNode.containerInfo;
|
||||
isContainer = true;
|
||||
case HostPortal: {
|
||||
const parent: Container = parentFiber.stateNode.containerInfo;
|
||||
const before = getHostSibling(finishedWork);
|
||||
insertOrAppendPlacementNodeIntoContainer(finishedWork, before, parent);
|
||||
break;
|
||||
}
|
||||
// eslint-disable-next-line-no-fallthrough
|
||||
default:
|
||||
throw new Error(
|
||||
@@ -1590,21 +1597,6 @@ function commitPlacement(finishedWork: Fiber): void {
|
||||
'in React. Please file an issue.',
|
||||
);
|
||||
}
|
||||
if (parentFiber.flags & ContentReset) {
|
||||
// Reset the text content of the parent before doing any insertions
|
||||
resetTextContent(parent);
|
||||
// Clear ContentReset from the effect tag
|
||||
parentFiber.flags &= ~ContentReset;
|
||||
}
|
||||
|
||||
const before = getHostSibling(finishedWork);
|
||||
// We only have the top Fiber that was inserted but we need to recurse down its
|
||||
// children to find all the terminal nodes.
|
||||
if (isContainer) {
|
||||
insertOrAppendPlacementNodeIntoContainer(finishedWork, before, parent);
|
||||
} else {
|
||||
insertOrAppendPlacementNode(finishedWork, before, parent);
|
||||
}
|
||||
}
|
||||
|
||||
function insertOrAppendPlacementNodeIntoContainer(
|
||||
|
||||
Reference in New Issue
Block a user