react-select icon indicating copy to clipboard operation
react-select copied to clipboard

Deprecated lifecycle method warnings with React 16.9

Open GreenGremlin opened this issue 7 years ago • 31 comments

The following warning is shown upon upgrading to React 16.9.0:

    Error: 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: Select in src/tests.entry.js (line 294578)

GreenGremlin avatar Aug 08 '19 22:08 GreenGremlin

I've got similar warning related to this one

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

      * Move data fetching code or side effects to componentDidUpdate.
      * If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state
      * Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps 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: AutosizeInput, Select

nukbal avatar Aug 09 '19 01:08 nukbal

That means you have component using legacy lifecycle OR you are using a library which uses the legacy lifecycle, I don't see this as an issue, in fact, it is helpful to identify legacy code and warn you when you do use libraries that do still.

jairusd avatar Aug 11 '19 17:08 jairusd

@jairusd react-select is the library with legacy methods.

TrySound avatar Aug 11 '19 17:08 TrySound

@JedWatson, since react 16.9.0 started to show a warning for deprecated lifecycles, is it possible that you create a patch release with a quick fix of renaming the deprecated lifecycles in order to remove the warning?

I've created a pull request (PR) for this: https://github.com/JedWatson/react-select/pull/3716

Note that this is just a quick fix for now to remove the warnings. It still requires a fix to move the code from the deprecated lifecycles to other related lifecycles.

Thanks

rj-david avatar Aug 11 '19 17:08 rj-david

oh sorry guys i was drunk when i made that comment

jairusd avatar Aug 12 '19 05:08 jairusd

What about running npx react-codemod rename-unsafe-lifecycles, will it work for libraries installed in node_modules?

tonix-tuft avatar Aug 18 '19 19:08 tonix-tuft

@tonix-tuft, I doubt if it would. If it does, it will be overwritten on your next npm ci or npm install

rj-david avatar Aug 19 '19 03:08 rj-david

By the way, my PR was merged to master. Just waiting for the next release

rj-david avatar Aug 19 '19 03:08 rj-david

@rj-david thanks!

alfred-pb avatar Aug 19 '19 05:08 alfred-pb

@tonix-tuft I ran npx react-codemod rename-unsafe-lifecycles where the warning was shown node_modules/react-dom ... but no results:

cs@cs-swift:~/work/react-best-practices/node_modules/react-dom$ npx react-codemod rename-unsafe-lifecycles
? On which files or directory should the codemods be applied? .
? Which dialect of JavaScript do you use? JavaScript
Executing command: jscodeshift --verbose=2 --ignore-pattern=**/node_modules/** --parser babel --extensions=jsx,js --transform /home/cs/.npm/_npx/31217/lib/node_modules/react-codemod/transforms/rename-unsafe-lifecycles.js .
Processing 36 files... 
Spawning 3 workers...
Sending 12 files to free worker...
Sending 12 files to free worker...
Sending 12 files to free worker...
 SKIP index.js
 SKIP profiling.js
 SKIP server.js
 SKIP server.node.js
 SKIP server.browser.js
 SKIP test-utils.js
 SKIP unstable-fizz.browser.js
 SKIP unstable-fizz.js
 SKIP unstable-fizz.node.js
 SKIP unstable-native-dependencies.js
 SKIP umd/react-dom-unstable-fizz.browser.development.js
 SKIP cjs/react-dom-unstable-fizz.browser.development.js
 SKIP umd/react-dom-unstable-fizz.browser.production.min.js
 SKIP cjs/react-dom-unstable-fizz.browser.production.min.js
 SKIP cjs/react-dom-unstable-fizz.node.development.js
 SKIP cjs/react-dom-unstable-fizz.node.production.min.js
 SKIP umd/react-dom-test-utils.production.min.js
 SKIP cjs/react-dom-test-utils.production.min.js
 SKIP umd/react-dom-unstable-native-dependencies.production.min.js
 SKIP cjs/react-dom-unstable-native-dependencies.production.min.js
 SKIP cjs/react-dom-server.browser.production.min.js
 SKIP umd/react-dom-server.browser.production.min.js
 SKIP cjs/react-dom-server.node.production.min.js
 SKIP cjs/react-dom-test-utils.development.js
 SKIP umd/react-dom-test-utils.development.js
 SKIP cjs/react-dom-unstable-native-dependencies.development.js
 SKIP umd/react-dom-unstable-native-dependencies.development.js
 SKIP cjs/react-dom-server.browser.development.js
 SKIP cjs/react-dom.profiling.min.js
 SKIP cjs/react-dom.production.min.js
 SKIP cjs/react-dom-server.node.development.js
 SKIP umd/react-dom.production.min.js
 SKIP umd/react-dom.profiling.min.js
 SKIP umd/react-dom-server.browser.development.js
 SKIP cjs/react-dom.development.js
 SKIP umd/react-dom.development.js
All done. 
Results: 
0 errors
0 unmodified
36 skipped
0 ok
Time elapsed: 17.457seconds 

metamn avatar Aug 21 '19 09:08 metamn

even using this "npx react-codemod rename-unsafe-lifecycles" ,the warning still persists..what should i do to avoid this warning?

ShajiKesavan avatar Aug 23 '19 04:08 ShajiKesavan

@gwyneplaine when can we expect this for a new release? Thanks

rj-david avatar Aug 23 '19 07:08 rj-david

the latest version of react-moment is also a library with this issue

zhenyu0519 avatar Aug 27 '19 01:08 zhenyu0519

@zhenyu0519, is that package a dependency of this package?

rj-david avatar Aug 27 '19 02:08 rj-david

oops. wrongs repo...

zachsa avatar Sep 04 '19 11:09 zachsa

@zhenyu0519, is that package a dependency of this package?

Sorry. I don't know what I was thinking. It's not.

zachsa avatar Sep 06 '19 20:09 zachsa

Thanks @gwyneplaine for merging #3716. Would you mind cutting a release with the change?

Also, is there any chance you're in touch with Jed and could help us get a similar fix for his other project, https://github.com/JedWatson/react-input-autosize/issues/163?

graue avatar Sep 07 '19 00:09 graue

I have same warning. I re-implement my component using react hooks but the warning is still showing. Anyone have same issue. These warning should not be shown in functional component.

chaudharykiran avatar Sep 10 '19 06:09 chaudharykiran

looking forward to see #3716 published to npm for the time being so my console is less cluttered! tnx everyone!

flyon avatar Sep 12 '19 15:09 flyon

+1 to hoping for a release soon to get rid of these. We've cleared out all of ours in our app, but waiting for all these dependencies to catch up so I can reclaim my console again.

blairmorris avatar Sep 18 '19 19:09 blairmorris