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

Function findCurrentFiberUsingSlowPath

bundle.js:5704–5730  ·  view source on GitHub ↗
(fiber)

Source from the content-addressed store, hash-verified

5702return MOUNTED;}// If we didn't hit the root, that means that we're in an disconnected tree
5703// that has been unmounted.
5704return UNMOUNTED;}var isFiberMounted=function isFiberMounted(fiber){return isFiberMountedImpl(fiber)===MOUNTED;};var isMounted=function isMounted(component){{var owner=ReactCurrentOwner.current;if(owner!==null&&owner.tag===ClassComponent){var ownerFiber=owner;var instance=ownerFiber.stateNode;warning$1(instance._warnedAboutRefsInRender,'%s is accessing isMounted inside its render() function. '+'render() should be a pure function of props and state. It should '+'never access something that requires stale data from the previous '+'render, such as refs. Move this logic to componentDidMount and '+'componentDidUpdate instead.',getComponentName_1(ownerFiber)||'A component');instance._warnedAboutRefsInRender=true;}}var fiber=ReactInstanceMap_1.get(component);if(!fiber){return false;}return isFiberMountedImpl(fiber)===MOUNTED;};function assertIsMounted(fiber){!(isFiberMountedImpl(fiber)===MOUNTED)?invariant(false,'Unable to find node on an unmounted component.'):void 0;}function findCurrentFiberUsingSlowPath(fiber){var alternate=fiber.alternate;if(!alternate){// If there is no alternate, then we only need to check if it is mounted.
5705var state=isFiberMountedImpl(fiber);!(state!==UNMOUNTED)?invariant(false,'Unable to find node on an unmounted component.'):void 0;if(state===MOUNTING){return null;}return fiber;}// If we have two possible branches, we'll walk backwards up to the root
5706// to see what path the root points to. On the way we may hit one of the
5707// special cases and we'll deal with them.
5708var a=fiber;var b=alternate;while(true){var parentA=a['return'];var parentB=parentA?parentA.alternate:null;if(!parentA||!parentB){// We're at the root.
5709break;}// If both copies of the parent fiber point to the same child, we can
5710// assume that the child is current. This happens when we bailout on low
5711// priority: the bailed out fiber's child reuses the current child.
5712if(parentA.child===parentB.child){var child=parentA.child;while(child){if(child===a){// We've determined that A is the current branch.
5713assertIsMounted(parentA);return fiber;}if(child===b){// We've determined that B is the current branch.
5714assertIsMounted(parentA);return alternate;}child=child.sibling;}// We should never have an alternate for any mounting node. So the only
5715// way this could possibly happen is if this was unmounted, if at all.
5716invariant(false,'Unable to find node on an unmounted component.');}if(a['return']!==b['return']){// The return pointer of A and the return pointer of B point to different
5717// fibers. We assume that return pointers never criss-cross, so A must
5718// belong to the child set of A.return, and B must belong to the child
5719// set of B.return.
5720a=parentA;b=parentB;}else{// The return pointers point to the same fiber. We'll have to use the
5721// default, slow path: scan the child sets of each parent alternate to see
5722// which child belongs to which set.
5723//
5724// Search parent A's child set
5725var didFindChild=false;var _child=parentA.child;while(_child){if(_child===a){didFindChild=true;a=parentA;b=parentB;break;}if(_child===b){didFindChild=true;b=parentA;a=parentB;break;}_child=_child.sibling;}if(!didFindChild){// Search parent B's child set
5726_child=parentB.child;while(_child){if(_child===a){didFindChild=true;a=parentB;b=parentA;break;}if(_child===b){didFindChild=true;b=parentB;a=parentA;break;}_child=_child.sibling;}!didFindChild?invariant(false,'Child was not found in either parent set. This indicates a bug in React related to the return pointer. Please file an issue.'):void 0;}}!(a.alternate===b)?invariant(false,'Return fibers should always be each others\' alternates. This error is likely caused by a bug in React. Please file an issue.'):void 0;}// If the root is not a host container, we're in a disconnected tree. I.e.
5727// unmounted.
5728!(a.tag===HostRoot$1)?invariant(false,'Unable to find node on an unmounted component.'):void 0;if(a.stateNode.current===a){// We've determined that A is the current branch.
5729return fiber;}// Otherwise B has to be current branch.
5730return alternate;}var findCurrentFiberUsingSlowPath_1=findCurrentFiberUsingSlowPath;var findCurrentHostFiber=function findCurrentHostFiber(parent){var currentParent=findCurrentFiberUsingSlowPath(parent);if(!currentParent){return null;}// Next we'll drill down this component to find the first HostComponent/Text.
5731var node=currentParent;while(true){if(node.tag===HostComponent$1||node.tag===HostText$1){return node;}else if(node.child){node.child['return']=node;node=node.child;continue;}if(node===currentParent){return null;}while(!node.sibling){if(!node['return']||node['return']===currentParent){return null;}node=node['return'];}node.sibling['return']=node['return'];node=node.sibling;}// Flow needs the return null here, but ESLint complains about it.
5732// eslint-disable-next-line no-unreachable
5733return null;};var findCurrentHostFiberWithNoPortals=function findCurrentHostFiberWithNoPortals(parent){var currentParent=findCurrentFiberUsingSlowPath(parent);if(!currentParent){return null;}// Next we'll drill down this component to find the first HostComponent/Text.

Callers 2

findCurrentHostFiberFunction · 0.85

Calls 3

isFiberMountedImplFunction · 0.85
assertIsMountedFunction · 0.85
invariantFunction · 0.70

Tested by

no test coverage detected