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

Function findCurrentFiberUsingSlowPath

code/third-party/public/app.js:4403–4513  ·  view source on GitHub ↗
(fiber)

Source from the content-addressed store, hash-verified

4401}
4402
4403function findCurrentFiberUsingSlowPath(fiber) {
4404 var alternate = fiber.alternate;
4405 if (!alternate) {
4406 // If there is no alternate, then we only need to check if it is mounted.
4407 var state = isFiberMountedImpl(fiber);
4408 !(state !== UNMOUNTED) ? invariant(false, 'Unable to find node on an unmounted component.') : void 0;
4409 if (state === MOUNTING) {
4410 return null;
4411 }
4412 return fiber;
4413 }
4414 // If we have two possible branches, we'll walk backwards up to the root
4415 // to see what path the root points to. On the way we may hit one of the
4416 // special cases and we'll deal with them.
4417 var a = fiber;
4418 var b = alternate;
4419 while (true) {
4420 var parentA = a['return'];
4421 var parentB = parentA ? parentA.alternate : null;
4422 if (!parentA || !parentB) {
4423 // We're at the root.
4424 break;
4425 }
4426
4427 // If both copies of the parent fiber point to the same child, we can
4428 // assume that the child is current. This happens when we bailout on low
4429 // priority: the bailed out fiber's child reuses the current child.
4430 if (parentA.child === parentB.child) {
4431 var child = parentA.child;
4432 while (child) {
4433 if (child === a) {
4434 // We've determined that A is the current branch.
4435 assertIsMounted(parentA);
4436 return fiber;
4437 }
4438 if (child === b) {
4439 // We've determined that B is the current branch.
4440 assertIsMounted(parentA);
4441 return alternate;
4442 }
4443 child = child.sibling;
4444 }
4445 // We should never have an alternate for any mounting node. So the only
4446 // way this could possibly happen is if this was unmounted, if at all.
4447 invariant(false, 'Unable to find node on an unmounted component.');
4448 }
4449
4450 if (a['return'] !== b['return']) {
4451 // The return pointer of A and the return pointer of B point to different
4452 // fibers. We assume that return pointers never criss-cross, so A must
4453 // belong to the child set of A.return, and B must belong to the child
4454 // set of B.return.
4455 a = parentA;
4456 b = parentB;
4457 } else {
4458 // The return pointers point to the same fiber. We'll have to use the
4459 // default, slow path: scan the child sets of each parent alternate to see
4460 // 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