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

Function unmountHostComponents

code/new-context-api/public/app.js:11088–11168  ·  view source on GitHub ↗
(current)

Source from the content-addressed store, hash-verified

11086 }
11087
11088 function unmountHostComponents(current) {
11089 // We only have the top Fiber that was inserted but we need recurse down its
11090 var node = current;
11091
11092 // Each iteration, currentParent is populated with node's host parent if not
11093 // currentParentIsValid.
11094 var currentParentIsValid = false;
11095 var currentParent = void 0;
11096 var currentParentIsContainer = void 0;
11097
11098 while (true) {
11099 if (!currentParentIsValid) {
11100 var parent = node['return'];
11101 findParent: while (true) {
11102 !(parent !== null) ? invariant(false, 'Expected to find a host parent. This error is likely caused by a bug in React. Please file an issue.') : void 0;
11103 switch (parent.tag) {
11104 case HostComponent:
11105 currentParent = parent.stateNode;
11106 currentParentIsContainer = false;
11107 break findParent;
11108 case HostRoot:
11109 currentParent = parent.stateNode.containerInfo;
11110 currentParentIsContainer = true;
11111 break findParent;
11112 case HostPortal:
11113 currentParent = parent.stateNode.containerInfo;
11114 currentParentIsContainer = true;
11115 break findParent;
11116 }
11117 parent = parent['return'];
11118 }
11119 currentParentIsValid = true;
11120 }
11121
11122 if (node.tag === HostComponent || node.tag === HostText) {
11123 commitNestedUnmounts(node);
11124 // After all the children have unmounted, it is now safe to remove the
11125 // node from the tree.
11126 if (currentParentIsContainer) {
11127 removeChildFromContainer(currentParent, node.stateNode);
11128 } else {
11129 removeChild(currentParent, node.stateNode);
11130 }
11131 // Don't visit children because we already visited them.
11132 } else if (node.tag === HostPortal) {
11133 // When we go into a portal, it becomes the parent to remove from.
11134 // We will reassign it back when we pop the portal on the way up.
11135 currentParent = node.stateNode.containerInfo;
11136 // Visit children because portals might contain host components.
11137 if (node.child !== null) {
11138 node.child['return'] = node;
11139 node = node.child;
11140 continue;
11141 }
11142 } else {
11143 commitUnmount(node);
11144 // Visit children because we may find more host components below.
11145 if (node.child !== null) {

Callers 2

commitUnmountFunction · 0.70
commitDeletionFunction · 0.70

Calls 3

invariantFunction · 0.70
commitNestedUnmountsFunction · 0.70
commitUnmountFunction · 0.70

Tested by

no test coverage detected