Skip to content

React.lazy: defaultProps not merged into props in commit phase lifecycles #13960

@variadicintegrity

Description

@variadicintegrity

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
In a component loaded using React.lazy, default props are not merged into the props object for these lifecycles:

  • componentDidMount
  • componentDidUpdate
  • componentWillUnmount
  • getSnapshotBeforeUpdate

In shouldComponentUpdate, default props are merged into the nextProps argument, but not this.props.

Steps to reproduce:

  1. Create a component that has a default value for a prop using defaultProps.
  2. Use that prop in one of the above lifecycles.
  3. Load the component using React.lazy.
  4. Observe that the prop is not defined in the above lifecycles.

CodeSandbox Link

What is the expected behavior?
Default props should be merged into props for all lifecycles when using React.lazy.

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
react 16.6.0
react-dom 16.6.0

Windows 10 Firefox 63.0
Windows 10 Chrome 70.0.3538.77

React.lazy was not in previous versions of React

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