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

Function unmountHostComponents

code/styling/public/app.js:11727–11807  ·  view source on GitHub ↗
(current)

Source from the content-addressed store, hash-verified

11725 }
11726
11727 function unmountHostComponents(current) {
11728 // We only have the top Fiber that was inserted but we need recurse down its
11729 var node = current;
11730
11731 // Each iteration, currentParent is populated with node's host parent if not
11732 // currentParentIsValid.
11733 var currentParentIsValid = false;
11734 var currentParent = void 0;
11735 var currentParentIsContainer = void 0;
11736
11737 while (true) {
11738 if (!currentParentIsValid) {
11739 var parent = node['return'];
11740 findParent: while (true) {
11741 !(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;
11742 switch (parent.tag) {
11743 case HostComponent:
11744 currentParent = parent.stateNode;
11745 currentParentIsContainer = false;
11746 break findParent;
11747 case HostRoot:
11748 currentParent = parent.stateNode.containerInfo;
11749 currentParentIsContainer = true;
11750 break findParent;
11751 case HostPortal:
11752 currentParent = parent.stateNode.containerInfo;
11753 currentParentIsContainer = true;
11754 break findParent;
11755 }
11756 parent = parent['return'];
11757 }
11758 currentParentIsValid = true;
11759 }
11760
11761 if (node.tag === HostComponent || node.tag === HostText) {
11762 commitNestedUnmounts(node);
11763 // After all the children have unmounted, it is now safe to remove the
11764 // node from the tree.
11765 if (currentParentIsContainer) {
11766 removeChildFromContainer(currentParent, node.stateNode);
11767 } else {
11768 removeChild(currentParent, node.stateNode);
11769 }
11770 // Don't visit children because we already visited them.
11771 } else if (node.tag === HostPortal) {
11772 // When we go into a portal, it becomes the parent to remove from.
11773 // We will reassign it back when we pop the portal on the way up.
11774 currentParent = node.stateNode.containerInfo;
11775 // Visit children because portals might contain host components.
11776 if (node.child !== null) {
11777 node.child['return'] = node;
11778 node = node.child;
11779 continue;
11780 }
11781 } else {
11782 commitUnmount(node);
11783 // Visit children because we may find more host components below.
11784 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