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
tweak unsafe lifecycle warnings #15431
Changes from all commits
c35e37a
dc605c1
a09bd0f
48ffcee
7cc1379
e86d051
e3b06c6
d884ec3
ea444d2
0523909
1ba1642
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,12 +141,18 @@ if (__DEV__) { | |
|
||
lowPriorityWarning( | ||
false, | ||
'componentWillMount is deprecated and will be removed in the next major version. ' + | ||
'Use componentDidMount instead. As a temporary workaround, ' + | ||
'you can rename to UNSAFE_componentWillMount.' + | ||
'\n\nPlease update the following components: %s' + | ||
'\n\nLearn more about this warning here:' + | ||
'\nhttps://fb.me/react-async-component-lifecycle-hooks', | ||
'componentWillMount has been renamed to UNSAFE_componentWillMount, ' + | ||
"and the old name won't work in the next major version of React.\n\n" + | ||
'We suggest doing one of the following:\n' + | ||
'- If you initialize state in componentWillMount, move this logic into the constructor.\n' + | ||
'- If you fetch data or perform other side effects in componentWillMount, ' + | ||
'move this logic into componentDidMount.\n' + | ||
'- To rename all deprecated lifecycles to their new names, you can run ' + | ||
'`npx react-codemod rename-unsafe-lifecycles <path/to/code>` in your project folder. ' + | ||
'(Note that the warning will still be logged in strict mode.)\n' + | ||
'\nPlease update the following components: %s\n' + | ||
'\nLearn more about this warning here:\n' + | ||
'https://fb.me/react-async-component-lifecycle-hooks', | ||
sortedNames, | ||
); | ||
|
||
|
@@ -164,11 +170,21 @@ if (__DEV__) { | |
|
||
lowPriorityWarning( | ||
false, | ||
'componentWillReceiveProps is deprecated and will be removed in the next major version. ' + | ||
'Use static getDerivedStateFromProps instead.' + | ||
'\n\nPlease update the following components: %s' + | ||
'\n\nLearn more about this warning here:' + | ||
'\nhttps://fb.me/react-async-component-lifecycle-hooks', | ||
'componentWillReceiveProps has been renamed to UNSAFE_componentWillReceiveProps, ' + | ||
"and the old name won't work in the next major version of React.\n\n" + | ||
'We suggest doing one of the following:\n' + | ||
"- If you're updating state whenever props change, " + | ||
'move this logic into static getDerivedStateFromProps.\n' + | ||
'- If you fetch data or perform other side effects in componentWillReceiveProps, ' + | ||
'move this logic into componentDidUpdate.\n' + | ||
'- Refactor your code to use memoization techniques instead of derived state. ' + | ||
'Learn more at: https://fb.me/react-derived-state\n' + | ||
'- To rename all deprecated lifecycles to their new names, you can run ' + | ||
'`npx react-codemod rename-unsafe-lifecycles <path/to/code>` in your project folder. ' + | ||
'(Note that the warning will still be logged in strict mode.)\n' + | ||
'\nPlease update the following components: %s\n' + | ||
'\nLearn more about this warning here:\n' + | ||
'https://fb.me/react-async-component-lifecycle-hooks', | ||
sortedNames, | ||
); | ||
|
||
|
@@ -186,12 +202,19 @@ if (__DEV__) { | |
|
||
lowPriorityWarning( | ||
false, | ||
'componentWillUpdate is deprecated and will be removed in the next major version. ' + | ||
'Use componentDidUpdate instead. As a temporary workaround, ' + | ||
'you can rename to UNSAFE_componentWillUpdate.' + | ||
'\n\nPlease update the following components: %s' + | ||
'\n\nLearn more about this warning here:' + | ||
'\nhttps://fb.me/react-async-component-lifecycle-hooks', | ||
'componentWillUpdate has been renamed to UNSAFE_componentWillUpdate, ' + | ||
"and the old name won't work in the next major version of React.\n\n" + | ||
'We suggest doing one of the following:\n' + | ||
'- If you fetch data or perform other side effects in componentWillUpdate, ' + | ||
'move this logic into componentDidUpdate.\n' + | ||
"- If you're reading DOM properties before an update, " + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Legit use cases for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I'll leave it here. We seem fairly comprehensive for the others, it would be frustrating if the dev had to go to a doc to discover a new api for just this one case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess I'm concerned that if people just move stuff to that method, without the added context of why it exists, they might be tempted to do mutations/side effects in it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They would probably try componentDidUpdate before that though? I dunno tbh. I could remove this, but seems like we should use same reasoning to remove getDerivedStateFromProps if so. |
||
'move this logic into getSnapshotBeforeUpdate.\n' + | ||
'- To rename all deprecated lifecycles to their new names, you can run ' + | ||
'`npx react-codemod rename-unsafe-lifecycles <path/to/code>` in your project folder. ' + | ||
'(Note that the warning will still be logged in strict mode.)\n' + | ||
'\nPlease update the following components: %s\n' + | ||
'\nLearn more about this warning here:\n' + | ||
'https://fb.me/react-async-component-lifecycle-hooks', | ||
sortedNames, | ||
); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should give a hint as to why folks might not want to just rename and ignore? Maybe we could replace
"To rename all deprecated lifecycles to their new names, ..."
...with
"To prevent this warning from being logged to the console, ..."
...so it sounds a little more like you're just choosing to ignore the warning without fixing the problem?
(here and below)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about "To ignore this warning from being logged to the console..."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather, "to disable this warning..."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's so wordy :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we're saying the warning will still log in strict mode, and that we've moved this to the bottom of the list, is sufficient. I'll fight you on this briannson.