-
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
Fix lazy() with defaultProps #14112
Fix lazy() with defaultProps #14112
Conversation
Btw this probably means DevTools would also be wrong since they read off |
ReactDOM: size: -4.6%, gzip: -5.1% Details of bundled changes.Comparing: fd1256a...40aeb2e react
react-dom
react-art
react-test-renderer
react-reconciler
create-subscription
react-native-renderer
scheduler
react-cache
Generated by 🚫 dangerJS |
@@ -12,6 +12,21 @@ import type {LazyComponent, Thenable} from 'shared/ReactLazyComponent'; | |||
import {Resolved, Rejected, Pending} from 'shared/ReactLazyComponent'; | |||
import warning from 'shared/warning'; | |||
|
|||
export function resolveDefaultProps(Component, baseProps) { |
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 this is not just used for lazy.
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.
Even if it was this would be the wrong place for it.
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 can move to shared and reuse from ReactElement too. Couldn’t find a nice existing place.
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 like shared. I prefer copying to putting things in shared. Makes it impossible to special case and encourages abstracting.
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.
So where do you want it? I guess I can create a file in the reconciler package but I don’t see why it deserves that when conceptually it’s related to our design for lazy.
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 kept it in LazyComponent
for now because I don't want to duplicate it in reconciler bundle twice.
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 should not be called all the time. Make it conditional on type not equaling elementType.
It made sense to do this lazily when we only did this on render. But now we do the work multiple times. Not sure that makes sense. |
0083e4b
to
ed49616
Compare
Pushed. |
This is an optimization. I'm not sure it's entirely safe. It's probably worth running internal tests and see if we can ever trigger a case where they're different. This can mess with resuming.
This reverts part of the previous commit. It broke a test that verifies we use current props in componentWillUnmount if the fiber unmounts due to an error.
* Resolve defaultProps for Lazy components * Make test fail again * Undo the partial fix * Make test output more compact * Add a separate failing test for sync mode * Clean up tests * Add another update to both tests * Resolve props for commit phase lifecycles * Resolve prevProps for begin phase lifecycles * Resolve prevProps for pre-commit lifecycles * Only resolve props if element type differs * Fix Flow * Don't set instance.props/state during commit phase This is an optimization. I'm not sure it's entirely safe. It's probably worth running internal tests and see if we can ever trigger a case where they're different. This can mess with resuming. * Keep setting instance.props/state before unmounting This reverts part of the previous commit. It broke a test that verifies we use current props in componentWillUnmount if the fiber unmounts due to an error.
* Resolve defaultProps for Lazy components * Make test fail again * Undo the partial fix * Make test output more compact * Add a separate failing test for sync mode * Clean up tests * Add another update to both tests * Resolve props for commit phase lifecycles * Resolve prevProps for begin phase lifecycles * Resolve prevProps for pre-commit lifecycles * Only resolve props if element type differs * Fix Flow * Don't set instance.props/state during commit phase This is an optimization. I'm not sure it's entirely safe. It's probably worth running internal tests and see if we can ever trigger a case where they're different. This can mess with resuming. * Keep setting instance.props/state before unmounting This reverts part of the previous commit. It broke a test that verifies we use current props in componentWillUnmount if the fiber unmounts due to an error.
Builds on failing tests from #14108.
Fixes #13960.
I might have missed something. Just pushing it before going home. I haven't thought about the perf impact of this. Maybe we need to change the strategy and store them?