-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
Remove extra loop (?) #11889
Remove extra loop (?) #11889
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,10 +27,7 @@ export function getClosestInstanceFromNode(node) { | |
return node[internalInstanceKey]; | ||
} | ||
|
||
// Walk up the tree until we find an ancestor whose instance we have cached. | ||
let parents = []; | ||
while (!node[internalInstanceKey]) { | ||
parents.push(node); | ||
if (node.parentNode) { | ||
node = node.parentNode; | ||
} else { | ||
|
@@ -40,17 +37,13 @@ export function getClosestInstanceFromNode(node) { | |
} | ||
} | ||
|
||
let closest; | ||
let inst = node[internalInstanceKey]; | ||
if (inst.tag === HostComponent || inst.tag === HostText) { | ||
// In Fiber, this will always be the deepest root. | ||
return inst; | ||
} | ||
for (; node && (inst = node[internalInstanceKey]); node = parents.pop()) { | ||
closest = inst; | ||
} | ||
|
||
return closest; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it make sense to return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's a good question. I think your probably right, however i was trying to keep with the spirit (for lack of a better term) of the method by failing softly. I do think tho that a situation where its not a component or text is kind of a different sort of error and maybe should fail hard. Are roots or portals cached on elements? Presumable you should hit a component before that tho |
||
return null; | ||
} | ||
|
||
/** | ||
|
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've tried to check back through the history to see what was going on here, and at least originally it used to try and precache nodes: 6d20556#diff-a2fd175216a5aa6425363e6773426f3c
But at some point that was removed but I can't find git blame is not helping :/
Then
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.
When does line 50 trigger?
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.
Sorry, I mean like what code path causes closest to be assigned to the instance? And what codepath even lets this function get past
return inst
on line 47?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 think in practical usage it doesn't get past 47, but I guess theoretically it could, if the fiber was a different type?
My guess tho is that this was for both stack and fiber and never got removed. Though even if it could get past 47 I don't think the loop does anything other than run one iteration, and return
inst
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.
Cool. I'd love to drop this if the code path no longer fires after Stack's removal. I'm afraid to ping anyone to bug them on holiday, but I think it's worth investigating.
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.
no rush clearly. :)
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.
It was hard to find due to a couple project reorganizations nuking the file history, but this was removed in #10798. I think the most likely explanation is that the whole loop could have been removed as well, but it wasn't clear that it was stack-only.
It's a little confusing, but at first glance it seems safe to remove 😄