-
Notifications
You must be signed in to change notification settings - Fork 47.6k
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
Don't recreate instance when resuming a class component's initial mount #9608
Conversation
87ceda5
to
2b1a0e3
Compare
newInstance.props = newProps; | ||
newInstance.state = newState = newInstance.state || null; | ||
newInstance.context = newContext; | ||
// componentWillMount may have called setState. Process the update queue. |
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 comment is in the wrong place. Do you mean componentWillReceiveProps
? If so, shouldn't this be gated on the existence of a componentWillReceiveProps
?
@@ -444,6 +496,9 @@ module.exports = function( | |||
if (typeof instance.componentDidMount === 'function') { | |||
workInProgress.effectTag |= Update; | |||
} | |||
|
|||
instance.state = newState; |
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.
If I do componentWillMount() { this.state = {}; }
What should it do?
664ea79
to
7526336
Compare
Recreating the class instance causes refs (and other callbacks) to close over stale instances. Instead, re-use the previous instance. componentWillMount is called again. We also call componentWillReceiveProps, to ensure that state derived from props remains in sync.
7526336
to
628b82c
Compare
**what is the change?:** A test was added for a change to Fiber's behavior in facebook#9608, and because of a bug in our CirclCI script it landed when failing for non-fiber runs of the tests. This just wraps the test in a feature flag because it seems clear it was only intended to test the new fiber behavior. Thanks to @gaearon for pairing on this! :) **why make this change?:** So that tests are passing on master. **test plan:** `npm run test ReactCompositeComponentState` **issue:** None - figured it out before anyone opened an issue afaik.
**what is the change?:** A test was added for a change to Fiber's behavior in facebook#9608, and because of a bug in our CirclCI script it landed when failing for non-fiber runs of the tests. This just wraps the test in a feature flag because it seems clear it was only intended to test the new fiber behavior. Thanks to @gaearon for pairing on this! :) **why make this change?:** So that tests are passing on master. **test plan:** `npm run test ReactCompositeComponentState` **issue:** None - figured it out before anyone opened an issue afaik.
**what is the change?:** A test was added for a change to Fiber's behavior in #9608, and because of a bug in our CirclCI script it landed when failing for non-fiber runs of the tests. This just wraps the test in a feature flag because it seems clear it was only intended to test the new fiber behavior. Thanks to @gaearon for pairing on this! :) **why make this change?:** So that tests are passing on master. **test plan:** `npm run test ReactCompositeComponentState` **issue:** None - figured it out before anyone opened an issue afaik.
Recreating the class instance causes refs (and other callbacks) to close over stale instances.
Instead, re-use the previous instance. componentWillMount is called again. We also call componentWillReceiveProps, to ensure that state derived from props remains in sync.