-
Notifications
You must be signed in to change notification settings - Fork 49.8k
Fixes bug when initial mount of a host component is hidden
#12294
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
Conversation
| // as the newProps. The updatePayload will contain the real change in | ||
| // this case. | ||
| const oldProps = current !== null ? current.memoizedProps : newProps; | ||
| let oldProps = current !== null ? current.memoizedProps : newProps; |
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.
Oops, forgot to delete :D
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.
Fixed
819b093 to
7ca44c9
Compare
| // we don't do the bailout and we have to reuse existing props instead. | ||
| } else if (memoizedProps === nextProps) { | ||
| return bailoutOnAlreadyFinishedWork(current, workInProgress); | ||
| if ( |
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.
renderExpirationTime === Offscreen?
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.
There's a test that fails when I do that, for some reason, haven't figured out why yet. Seems like it should do the same thing, since it will end up bailing out a few lines below, anyway.
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.
Ah figured it out
| workInProgress.mode & AsyncMode && | ||
| shouldDeprioritizeSubtree(type, nextProps) | ||
| ) { | ||
| // Don't bail-out if this is hidden |
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.
As a general style guide we should invert this logic and remove the dead block because it is not always possible for the compiler to invert these conditionals and strip the extra code. Due to things like !(NaN > NaN) isn't the same as NaN <= NaN
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 mean it is always possible to wrap in !() but those three extra bytes can't be reclaimed.
7ca44c9 to
1a039f2
Compare
| workInProgress.mode & AsyncMode && | ||
| shouldDeprioritizeSubtree(type, nextProps) | ||
| ) { | ||
| if (renderExpirationTime === Never) { |
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.
This condition should be first because it is the fastest one. No property access.
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.
Ha, I was trying to avoid assigning the result of shouldDeprioritizeSubtree to a boolean :D
607100f to
ed4c171
Compare
`oldProps` was null. This went uncaught by the unit tests because ReactNoop did not use `oldProps` in either `prepareUpdate` or `completeUpdate`. I added some invariants so we don't regress in the future.
ed4c171 to
122a187
Compare
| } | ||
| if (newProps === null) { | ||
| throw new Error('Should have old props'); | ||
| } |
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.
Should be
if (oldProps === null || newProps === null) {
throw new Error('Should have old props');
}
?
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.
Second one is a typo.
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.
Yea, #12590
oldPropswas null. This went uncaught by the unit tests because ReactNoop did not useoldPropsin eitherprepareUpdateorcompleteUpdate. I added some invariants so we don't regress in the future.