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

Function findCurrentFiberUsingSlowPath

code/redux/public/app.js:5421–5531  ·  view source on GitHub ↗
(fiber)

Source from the content-addressed store, hash-verified

5419}
5420
5421function findCurrentFiberUsingSlowPath(fiber) {
5422 var alternate = fiber.alternate;
5423 if (!alternate) {
5424 // If there is no alternate, then we only need to check if it is mounted.
5425 var state = isFiberMountedImpl(fiber);
5426 !(state !== UNMOUNTED) ? invariant(false, 'Unable to find node on an unmounted component.') : void 0;
5427 if (state === MOUNTING) {
5428 return null;
5429 }
5430 return fiber;
5431 }
5432 // If we have two possible branches, we'll walk backwards up to the root
5433 // to see what path the root points to. On the way we may hit one of the
5434 // special cases and we'll deal with them.
5435 var a = fiber;
5436 var b = alternate;
5437 while (true) {
5438 var parentA = a['return'];
5439 var parentB = parentA ? parentA.alternate : null;
5440 if (!parentA || !parentB) {
5441 // We're at the root.
5442 break;
5443 }
5444
5445 // If both copies of the parent fiber point to the same child, we can
5446 // assume that the child is current. This happens when we bailout on low
5447 // priority: the bailed out fiber's child reuses the current child.
5448 if (parentA.child === parentB.child) {
5449 var child = parentA.child;
5450 while (child) {
5451 if (child === a) {
5452 // We've determined that A is the current branch.
5453 assertIsMounted(parentA);
5454 return fiber;
5455 }
5456 if (child === b) {
5457 // We've determined that B is the current branch.
5458 assertIsMounted(parentA);
5459 return alternate;
5460 }
5461 child = child.sibling;
5462 }
5463 // We should never have an alternate for any mounting node. So the only
5464 // way this could possibly happen is if this was unmounted, if at all.
5465 invariant(false, 'Unable to find node on an unmounted component.');
5466 }
5467
5468 if (a['return'] !== b['return']) {
5469 // The return pointer of A and the return pointer of B point to different
5470 // fibers. We assume that return pointers never criss-cross, so A must
5471 // belong to the child set of A.return, and B must belong to the child
5472 // set of B.return.
5473 a = parentA;
5474 b = parentB;
5475 } else {
5476 // The return pointers point to the same fiber. We'll have to use the
5477 // default, slow path: scan the child sets of each parent alternate to see
5478 // which child belongs to which set.

Callers 2

findCurrentHostFiberFunction · 0.70

Calls 3

isFiberMountedImplFunction · 0.70
invariantFunction · 0.70
assertIsMountedFunction · 0.70

Tested by

no test coverage detected