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

Function findCurrentFiberUsingSlowPath

code/styling/public/app.js:5170–5280  ·  view source on GitHub ↗
(fiber)

Source from the content-addressed store, hash-verified

5168}
5169
5170function findCurrentFiberUsingSlowPath(fiber) {
5171 var alternate = fiber.alternate;
5172 if (!alternate) {
5173 // If there is no alternate, then we only need to check if it is mounted.
5174 var state = isFiberMountedImpl(fiber);
5175 !(state !== UNMOUNTED) ? invariant(false, 'Unable to find node on an unmounted component.') : void 0;
5176 if (state === MOUNTING) {
5177 return null;
5178 }
5179 return fiber;
5180 }
5181 // If we have two possible branches, we'll walk backwards up to the root
5182 // to see what path the root points to. On the way we may hit one of the
5183 // special cases and we'll deal with them.
5184 var a = fiber;
5185 var b = alternate;
5186 while (true) {
5187 var parentA = a['return'];
5188 var parentB = parentA ? parentA.alternate : null;
5189 if (!parentA || !parentB) {
5190 // We're at the root.
5191 break;
5192 }
5193
5194 // If both copies of the parent fiber point to the same child, we can
5195 // assume that the child is current. This happens when we bailout on low
5196 // priority: the bailed out fiber's child reuses the current child.
5197 if (parentA.child === parentB.child) {
5198 var child = parentA.child;
5199 while (child) {
5200 if (child === a) {
5201 // We've determined that A is the current branch.
5202 assertIsMounted(parentA);
5203 return fiber;
5204 }
5205 if (child === b) {
5206 // We've determined that B is the current branch.
5207 assertIsMounted(parentA);
5208 return alternate;
5209 }
5210 child = child.sibling;
5211 }
5212 // We should never have an alternate for any mounting node. So the only
5213 // way this could possibly happen is if this was unmounted, if at all.
5214 invariant(false, 'Unable to find node on an unmounted component.');
5215 }
5216
5217 if (a['return'] !== b['return']) {
5218 // The return pointer of A and the return pointer of B point to different
5219 // fibers. We assume that return pointers never criss-cross, so A must
5220 // belong to the child set of A.return, and B must belong to the child
5221 // set of B.return.
5222 a = parentA;
5223 b = parentB;
5224 } else {
5225 // The return pointers point to the same fiber. We'll have to use the
5226 // default, slow path: scan the child sets of each parent alternate to see
5227 // 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