MCPcopy Create free account
hub / github.com/krasimir/react-in-patterns / commitPlacement

Function commitPlacement

code/new-context-api/public/app.js:11018–11086  ·  view source on GitHub ↗
(finishedWork)

Source from the content-addressed store, hash-verified

11016 }
11017
11018 function commitPlacement(finishedWork) {
11019 // Recursively insert all host nodes into the parent.
11020 var parentFiber = getHostParentFiber(finishedWork);
11021 var parent = void 0;
11022 var isContainer = void 0;
11023 switch (parentFiber.tag) {
11024 case HostComponent:
11025 parent = parentFiber.stateNode;
11026 isContainer = false;
11027 break;
11028 case HostRoot:
11029 parent = parentFiber.stateNode.containerInfo;
11030 isContainer = true;
11031 break;
11032 case HostPortal:
11033 parent = parentFiber.stateNode.containerInfo;
11034 isContainer = true;
11035 break;
11036 default:
11037 invariant(false, 'Invalid host parent fiber. This error is likely caused by a bug in React. Please file an issue.');
11038 }
11039 if (parentFiber.effectTag & ContentReset) {
11040 // Reset the text content of the parent before doing any insertions
11041 resetTextContent(parent);
11042 // Clear ContentReset from the effect tag
11043 parentFiber.effectTag &= ~ContentReset;
11044 }
11045
11046 var before = getHostSibling(finishedWork);
11047 // We only have the top Fiber that was inserted but we need recurse down its
11048 // children to find all the terminal nodes.
11049 var node = finishedWork;
11050 while (true) {
11051 if (node.tag === HostComponent || node.tag === HostText) {
11052 if (before) {
11053 if (isContainer) {
11054 insertInContainerBefore(parent, node.stateNode, before);
11055 } else {
11056 insertBefore(parent, node.stateNode, before);
11057 }
11058 } else {
11059 if (isContainer) {
11060 appendChildToContainer(parent, node.stateNode);
11061 } else {
11062 appendChild(parent, node.stateNode);
11063 }
11064 }
11065 } else if (node.tag === HostPortal) {
11066 // If the insertion itself is a portal, then we don't want to traverse
11067 // down its children. Instead, we'll get insertions from each child in
11068 // the portal directly.
11069 } else if (node.child !== null) {
11070 node.child['return'] = node;
11071 node = node.child;
11072 continue;
11073 }
11074 if (node === finishedWork) {
11075 return;

Callers 1

commitAllHostEffectsFunction · 0.70

Calls 3

getHostParentFiberFunction · 0.70
invariantFunction · 0.70
getHostSiblingFunction · 0.70

Tested by

no test coverage detected