Skip to content

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

Closed
@Hypnosphi

Description

@Hypnosphi

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,
};

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions