Skip to content

componentWillMount usage in loadable.js is deprecated in react 16.9.0 #8310

@tm1000

Description

@tm1000

Bug report

Describe the bug

Starting in React 16.9.0 using 'componentWillMount' issues a deprecation warning because it has been renamed to UNSAFE_componentWillMount. Instead it is suggested to use componentDidMount.

This was discovered by using dynamic imports with react 16.9.0 (Released yesterday) and nextjs 9.0.3

Full error is

Warning: componentWillMount has been renamed, and is not recommended for use. See https://fb.me/react-async-component-lifecycle-hooks for details.

  • Move code with side effects to componentDidMount, and set initial state in the constructor.
  • Rename componentWillMount to UNSAFE_componentWillMount to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run npx react-codemod rename-unsafe-lifecycles in your project source folder.

Please update the following components: LoadableComponent

Code Reference:
https://github.com/zeit/next.js/blob/master/packages/next-server/lib/loadable.js#L174

To Reproduce

npm install react react-dom next

Then just add a dynamic import

import React from 'react';
const DynamicComponent = dynamic(() => import(`./file`), {
	loading: () => '<div>Loading Component</div>',
});
function TestComponent() {
	return <DynamicComponent />
}
export default TestComponent;

Expected behavior

loadable.js should be fixed to either work with componentDidMount (See comment below) or UNSAFE_componentWillMount

Screenshots

image

System information

  • Version of Next.js: 9.0.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions