(fiber)
| 4935 | } |
| 4936 | |
| 4937 | function findCurrentFiberUsingSlowPath(fiber) { |
| 4938 | var alternate = fiber.alternate; |
| 4939 | if (!alternate) { |
| 4940 | // If there is no alternate, then we only need to check if it is mounted. |
| 4941 | var state = isFiberMountedImpl(fiber); |
| 4942 | !(state !== UNMOUNTED) ? invariant(false, 'Unable to find node on an unmounted component.') : void 0; |
| 4943 | if (state === MOUNTING) { |
| 4944 | return null; |
| 4945 | } |
| 4946 | return fiber; |
| 4947 | } |
| 4948 | // If we have two possible branches, we'll walk backwards up to the root |
| 4949 | // to see what path the root points to. On the way we may hit one of the |
| 4950 | // special cases and we'll deal with them. |
| 4951 | var a = fiber; |
| 4952 | var b = alternate; |
| 4953 | while (true) { |
| 4954 | var parentA = a.return; |
| 4955 | var parentB = parentA ? parentA.alternate : null; |
| 4956 | if (!parentA || !parentB) { |
| 4957 | // We're at the root. |
| 4958 | break; |
| 4959 | } |
| 4960 | |
| 4961 | // If both copies of the parent fiber point to the same child, we can |
| 4962 | // assume that the child is current. This happens when we bailout on low |
| 4963 | // priority: the bailed out fiber's child reuses the current child. |
| 4964 | if (parentA.child === parentB.child) { |
| 4965 | var child = parentA.child; |
| 4966 | while (child) { |
| 4967 | if (child === a) { |
| 4968 | // We've determined that A is the current branch. |
| 4969 | assertIsMounted(parentA); |
| 4970 | return fiber; |
| 4971 | } |
| 4972 | if (child === b) { |
| 4973 | // We've determined that B is the current branch. |
| 4974 | assertIsMounted(parentA); |
| 4975 | return alternate; |
| 4976 | } |
| 4977 | child = child.sibling; |
| 4978 | } |
| 4979 | // We should never have an alternate for any mounting node. So the only |
| 4980 | // way this could possibly happen is if this was unmounted, if at all. |
| 4981 | invariant(false, 'Unable to find node on an unmounted component.'); |
| 4982 | } |
| 4983 | |
| 4984 | if (a.return !== b.return) { |
| 4985 | // The return pointer of A and the return pointer of B point to different |
| 4986 | // fibers. We assume that return pointers never criss-cross, so A must |
| 4987 | // belong to the child set of A.return, and B must belong to the child |
| 4988 | // set of B.return. |
| 4989 | a = parentA; |
| 4990 | b = parentB; |
| 4991 | } else { |
| 4992 | // The return pointers point to the same fiber. We'll have to use the |
| 4993 | // default, slow path: scan the child sets of each parent alternate to see |
| 4994 | // which child belongs to which set. |
no test coverage detected