MCPcopy Create free account
hub / github.com/danielstocks/react-sortable / ReactFiberCommitWork

Function ReactFiberCommitWork

bundle.js:7546–7613  ·  view source on GitHub ↗
(config,captureError)

Source from the content-addressed store, hash-verified

7544onCommitFiberRoot=catchErrors(function(root){return hook.onCommitFiberRoot(rendererID,root);});onCommitFiberUnmount=catchErrors(function(fiber){return hook.onCommitFiberUnmount(rendererID,fiber);});}catch(err){// Catch all errors because it is unsafe to throw during initialization.
7545{warning$26(false,'React DevTools encountered an error: %s.',err);}}// DevTools exists
7546return true;}function onCommitRoot$1(root){if(typeof onCommitFiberRoot==='function'){onCommitFiberRoot(root);}}function onCommitUnmount$1(fiber){if(typeof onCommitFiberUnmount==='function'){onCommitFiberUnmount(fiber);}}var injectInternals_1=injectInternals$1;var onCommitRoot_1=onCommitRoot$1;var onCommitUnmount_1=onCommitUnmount$1;var ReactFiberDevToolsHook={injectInternals:injectInternals_1,onCommitRoot:onCommitRoot_1,onCommitUnmount:onCommitUnmount_1};var ClassComponent$9=ReactTypeOfWork.ClassComponent;var HostRoot$9=ReactTypeOfWork.HostRoot;var HostComponent$9=ReactTypeOfWork.HostComponent;var HostText$7=ReactTypeOfWork.HostText;var HostPortal$7=ReactTypeOfWork.HostPortal;var CoroutineComponent$4=ReactTypeOfWork.CoroutineComponent;var commitCallbacks$1=ReactFiberUpdateQueue.commitCallbacks;var onCommitUnmount=ReactFiberDevToolsHook.onCommitUnmount;var invokeGuardedCallback$2=ReactErrorUtils_1.invokeGuardedCallback;var hasCaughtError$1=ReactErrorUtils_1.hasCaughtError;var clearCaughtError$1=ReactErrorUtils_1.clearCaughtError;var Placement$5=ReactTypeOfSideEffect.Placement;var Update$3=ReactTypeOfSideEffect.Update;var Callback$1=ReactTypeOfSideEffect.Callback;var ContentReset$2=ReactTypeOfSideEffect.ContentReset;{var _require5$1=ReactDebugFiberPerf_1,startPhaseTimer$2=_require5$1.startPhaseTimer,stopPhaseTimer$2=_require5$1.stopPhaseTimer;}var ReactFiberCommitWork=function ReactFiberCommitWork(config,captureError){var commitMount=config.commitMount,commitUpdate=config.commitUpdate,resetTextContent=config.resetTextContent,commitTextUpdate=config.commitTextUpdate,appendChild=config.appendChild,appendChildToContainer=config.appendChildToContainer,insertBefore=config.insertBefore,insertInContainerBefore=config.insertInContainerBefore,removeChild=config.removeChild,removeChildFromContainer=config.removeChildFromContainer,getPublicInstance=config.getPublicInstance;{var callComponentWillUnmountWithTimerInDev=function callComponentWillUnmountWithTimerInDev(current,instance){startPhaseTimer$2(current,'componentWillUnmount');instance.props=current.memoizedProps;instance.state=current.memoizedState;instance.componentWillUnmount();stopPhaseTimer$2();};}// Capture errors so they don't interrupt unmounting.
7547function safelyCallComponentWillUnmount(current,instance){{invokeGuardedCallback$2(null,callComponentWillUnmountWithTimerInDev,null,current,instance);if(hasCaughtError$1()){var unmountError=clearCaughtError$1();captureError(current,unmountError);}}}function safelyDetachRef(current){var ref=current.ref;if(ref!==null){{invokeGuardedCallback$2(null,ref,null,null);if(hasCaughtError$1()){var refError=clearCaughtError$1();captureError(current,refError);}}}}function getHostParentFiber(fiber){var parent=fiber['return'];while(parent!==null){if(isHostParent(parent)){return parent;}parent=parent['return'];}invariant(false,'Expected to find a host parent. This error is likely caused by a bug in React. Please file an issue.');}function isHostParent(fiber){return fiber.tag===HostComponent$9||fiber.tag===HostRoot$9||fiber.tag===HostPortal$7;}function getHostSibling(fiber){// We're going to search forward into the tree until we find a sibling host
7548// node. Unfortunately, if multiple insertions are done in a row we have to
7549// search past them. This leads to exponential search for the next sibling.
7550var node=fiber;siblings:while(true){// If we didn't find anything, let's try the next sibling.
7551while(node.sibling===null){if(node['return']===null||isHostParent(node['return'])){// If we pop out of the root or hit the parent the fiber we are the
7552// last sibling.
7553return null;}node=node['return'];}node.sibling['return']=node['return'];node=node.sibling;while(node.tag!==HostComponent$9&&node.tag!==HostText$7){// If it is not host node and, we might have a host node inside it.
7554// Try to search down until we find one.
7555if(node.effectTag&Placement$5){// If we don't have a child, try the siblings instead.
7556continue siblings;}// If we don't have a child, try the siblings instead.
7557// We also skip portals because they are not part of this host tree.
7558if(node.child===null||node.tag===HostPortal$7){continue siblings;}else{node.child['return']=node;node=node.child;}}// Check if this host node is stable or about to be placed.
7559if(!(node.effectTag&Placement$5)){// Found it!
7560return node.stateNode;}}}function commitPlacement(finishedWork){// Recursively insert all host nodes into the parent.
7561var parentFiber=getHostParentFiber(finishedWork);var parent=void 0;var isContainer=void 0;switch(parentFiber.tag){case HostComponent$9:parent=parentFiber.stateNode;isContainer=false;break;case HostRoot$9:parent=parentFiber.stateNode.containerInfo;isContainer=true;break;case HostPortal$7:parent=parentFiber.stateNode.containerInfo;isContainer=true;break;default:invariant(false,'Invalid host parent fiber. This error is likely caused by a bug in React. Please file an issue.');}if(parentFiber.effectTag&ContentReset$2){// Reset the text content of the parent before doing any insertions
7562resetTextContent(parent);// Clear ContentReset from the effect tag
7563parentFiber.effectTag&=~ContentReset$2;}var before=getHostSibling(finishedWork);// We only have the top Fiber that was inserted but we need recurse down its
7564// children to find all the terminal nodes.
7565var node=finishedWork;while(true){if(node.tag===HostComponent$9||node.tag===HostText$7){if(before){if(isContainer){insertInContainerBefore(parent,node.stateNode,before);}else{insertBefore(parent,node.stateNode,before);}}else{if(isContainer){appendChildToContainer(parent,node.stateNode);}else{appendChild(parent,node.stateNode);}}}else if(node.tag===HostPortal$7){// If the insertion itself is a portal, then we don't want to traverse
7566// down its children. Instead, we'll get insertions from each child in
7567// the portal directly.
7568}else if(node.child!==null){node.child['return']=node;node=node.child;continue;}if(node===finishedWork){return;}while(node.sibling===null){if(node['return']===null||node['return']===finishedWork){return;}node=node['return'];}node.sibling['return']=node['return'];node=node.sibling;}}function commitNestedUnmounts(root){// While we're inside a removed host node we don't want to call
7569// removeChild on the inner nodes because they're removed by the top
7570// call anyway. We also want to call componentWillUnmount on all
7571// composites before this host node is removed from the tree. Therefore
7572var node=root;while(true){commitUnmount(node);// Visit children because they may contain more composite or host nodes.
7573// Skip portals because commitUnmount() currently visits them recursively.
7574if(node.child!==null&&node.tag!==HostPortal$7){node.child['return']=node;node=node.child;continue;}if(node===root){return;}while(node.sibling===null){if(node['return']===null||node['return']===root){return;}node=node['return'];}node.sibling['return']=node['return'];node=node.sibling;}}function unmountHostComponents(current){// We only have the top Fiber that was inserted but we need recurse down its
7575var node=current;// Each iteration, currentParent is populated with node's host parent if not
7576// currentParentIsValid.
7577var currentParentIsValid=false;var currentParent=void 0;var currentParentIsContainer=void 0;while(true){if(!currentParentIsValid){var parent=node['return'];findParent:while(true){!(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;switch(parent.tag){case HostComponent$9:currentParent=parent.stateNode;currentParentIsContainer=false;break findParent;case HostRoot$9:currentParent=parent.stateNode.containerInfo;currentParentIsContainer=true;break findParent;case HostPortal$7:currentParent=parent.stateNode.containerInfo;currentParentIsContainer=true;break findParent;}parent=parent['return'];}currentParentIsValid=true;}if(node.tag===HostComponent$9||node.tag===HostText$7){commitNestedUnmounts(node);// After all the children have unmounted, it is now safe to remove the
7578// node from the tree.
7579if(currentParentIsContainer){removeChildFromContainer(currentParent,node.stateNode);}else{removeChild(currentParent,node.stateNode);}// Don't visit children because we already visited them.
7580}else if(node.tag===HostPortal$7){// When we go into a portal, it becomes the parent to remove from.
7581// We will reassign it back when we pop the portal on the way up.
7582currentParent=node.stateNode.containerInfo;// Visit children because portals might contain host components.
7583if(node.child!==null){node.child['return']=node;node=node.child;continue;}}else{commitUnmount(node);// Visit children because we may find more host components below.
7584if(node.child!==null){node.child['return']=node;node=node.child;continue;}}if(node===current){return;}while(node.sibling===null){if(node['return']===null||node['return']===current){return;}node=node['return'];if(node.tag===HostPortal$7){// When we go out of the portal, we need to restore the parent.
7585// Since we don't keep a stack of them, we will search for it.
7586currentParentIsValid=false;}}node.sibling['return']=node['return'];node=node.sibling;}}function commitDeletion(current){// Recursively delete all host nodes from the parent.
7587// Detach refs and call componentWillUnmount() on the whole subtree.
7588unmountHostComponents(current);// Cut off the return pointers to disconnect it from the tree. Ideally, we
7589// should clear the child pointer of the parent alternate to let this
7590// get GC:ed but we don't know which for sure which parent is the current
7591// one so we'll settle for GC:ing the subtree of this child. This child
7592// itself will be GC:ed when the parent updates the next time.
7593current['return']=null;current.child=null;if(current.alternate){current.alternate.child=null;current.alternate['return']=null;}}// User-originating errors (lifecycles and refs) should not interrupt
7594// deletion, so don't let them throw. Host-originating errors should
7595// interrupt deletion, so it's okay
7596function commitUnmount(current){if(typeof onCommitUnmount==='function'){onCommitUnmount(current);}switch(current.tag){case ClassComponent$9:{safelyDetachRef(current);var instance=current.stateNode;if(typeof instance.componentWillUnmount==='function'){safelyCallComponentWillUnmount(current,instance);}return;}case HostComponent$9:{safelyDetachRef(current);return;}case CoroutineComponent$4:{commitNestedUnmounts(current.stateNode);return;}case HostPortal$7:{// TODO: this is recursive.
7597// We are also not using this parent because
7598// the portal will get pushed immediately.
7599unmountHostComponents(current);return;}}}function commitWork(current,finishedWork){switch(finishedWork.tag){case ClassComponent$9:{return;}case HostComponent$9:{var instance=finishedWork.stateNode;if(instance!=null){// Commit the work prepared earlier.
7600var newProps=finishedWork.memoizedProps;// For hydration we reuse the update path but we treat the oldProps
7601// as the newProps. The updatePayload will contain the real change in
7602// this case.
7603var oldProps=current!==null?current.memoizedProps:newProps;var type=finishedWork.type;// TODO: Type the updateQueue to be specific to host components.

Callers 1

ReactFiberSchedulerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected