Skip to content
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

Shallow renderer: subsequent setState calls inside componentWillMount discard the previous ones #11161

Closed
Hypnosphi opened this issue Oct 9, 2017 · 4 comments

Comments

@Hypnosphi
Copy link
Contributor

Hypnosphi commented Oct 9, 2017

What is the current behavior?

If componentWillMount has multiple setState calls, only the last one works in shallow renderer

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem
https://www.webpackbin.com/bins/-Kw11Ya_ZJ1BcL0rpDKj

Here, DOM renderer correctly renders "Hello, world" while test shallow renderer renders "undefined, world".

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
Issue is introduced in React 16.

The reason must be those lines, replacing publicInstance.state with this._renderer._newState should fix it:

this._renderer._newState = {
...publicInstance.state,
...partialState,
};

@Hypnosphi Hypnosphi changed the title Shallow renderer: subsequent setState calls inside componentWillUpdate discard the previous ones Shallow renderer: subsequent setState calls inside componentWillMount discard the previous ones Oct 9, 2017
@gaearon
Copy link
Collaborator

gaearon commented Oct 9, 2017

Want to send a PR?

@Hypnosphi
Copy link
Contributor Author

Sure, will do

@gaearon
Copy link
Collaborator

gaearon commented Oct 10, 2017

Fixed by #11167.

@gaearon gaearon closed this as completed Oct 10, 2017
@gaearon
Copy link
Collaborator

gaearon commented Nov 3, 2017

React 16.1.0-beta has been released. Please update react, react-dom, and react-test-renderer (if you use it) to this version and let us know if it solved the issue! We’d appreciate if you could test before Monday when we plan to get 16.1.0 out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants