-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Revert "Merge pull request #1399 from aweary/use-react-reconciler-rea… #1778
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
packages/enzyme-adapter-react-16/src/findCurrentFiberUsingSlowPath.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// Extracted from https://github.com/facebook/react/blob/7bdf93b17a35a5d8fcf0ceae0bf48ed5e6b16688/src/renderers/shared/fiber/ReactFiberTreeReflection.js#L104-L228 | ||
function findCurrentFiberUsingSlowPath(fiber) { | ||
const { alternate } = fiber; | ||
if (!alternate) { | ||
return fiber; | ||
} | ||
// If we have two possible branches, we'll walk backwards up to the root | ||
// to see what path the root points to. On the way we may hit one of the | ||
// special cases and we'll deal with them. | ||
let a = fiber; | ||
let b = alternate; | ||
while (true) { // eslint-disable-line | ||
const parentA = a.return; | ||
const parentB = parentA ? parentA.alternate : null; | ||
if (!parentA || !parentB) { | ||
// We're at the root. | ||
break; | ||
} | ||
|
||
// If both copies of the parent fiber point to the same child, we can | ||
// assume that the child is current. This happens when we bailout on low | ||
// priority: the bailed out fiber's child reuses the current child. | ||
if (parentA.child === parentB.child) { | ||
let { child } = parentA; | ||
while (child) { | ||
if (child === a) { | ||
// We've determined that A is the current branch. | ||
return fiber; | ||
} | ||
if (child === b) { | ||
// We've determined that B is the current branch. | ||
return alternate; | ||
} | ||
child = child.sibling; | ||
} | ||
// We should never have an alternate for any mounting node. So the only | ||
// way this could possibly happen is if this was unmounted, if at all. | ||
throw new Error('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 | ||
// fibers. We assume that return pointers never criss-cross, so A must | ||
// belong to the child set of A.return, and B must belong to the child | ||
// set of B.return. | ||
a = parentA; | ||
b = parentB; | ||
} else { | ||
// The return pointers point to the same fiber. We'll have to use the | ||
// default, slow path: scan the child sets of each parent alternate to see | ||
// which child belongs to which set. | ||
// | ||
// Search parent A's child set | ||
let didFindChild = false; | ||
let { child } = parentA; | ||
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 | ||
({ child } = parentB); | ||
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; | ||
} | ||
if (!didFindChild) { | ||
throw new Error('Child was not found in either parent set. This indicates a bug ' | ||
+ 'in React related to the return pointer. Please file an issue.'); | ||
} | ||
} | ||
} | ||
} | ||
if (a.stateNode.current === a) { | ||
// We've determined that A is the current branch. | ||
return fiber; | ||
} | ||
// Otherwise B has to be current branch. | ||
return alternate; | ||
} | ||
|
||
module.exports = findCurrentFiberUsingSlowPath; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why this is an improvement - we were locked to v0.7.0 before, and now this is just inlining it. Why can't this be pulled from react-reconciler, or why can't react-reconciler be updated?