-
Notifications
You must be signed in to change notification settings - Fork 47k
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
Don't fire the render phase update warning for class lifecycles #18330
Conversation
This warning is more generic and may happen with class components too.
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 933157f:
|
…book#18330) * Change the warning to not say "function body" This warning is more generic and may happen with class components too. * Dedupe by the rendering component * Don't warn outside of render
…book#18330) * Change the warning to not say "function body" This warning is more generic and may happen with class components too. * Dedupe by the rendering component * Don't warn outside of render
…book#18330) * Change the warning to not say "function body" This warning is more generic and may happen with class components too. * Dedupe by the rendering component * Don't warn outside of render
@@ -1372,6 +1373,7 @@ function mountIndeterminateComponent( | |||
context, | |||
renderExpirationTime, | |||
); | |||
setIsRendering(false); |
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.
If the component throws, setIsRendering
won't be reset. This needs to be reset in the the work loop. Here:
react/packages/react-reconciler/src/ReactFiberWorkLoop.js
Lines 1226 to 1229 in 8311cb5
// Reset module-level state that was set during the render phase. | |
resetContextDependencies(); | |
resetHooksAfterThrow(); | |
resetCurrentDebugFiberInDEV(); |
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.
Never mind, gets reset by resetCurrentDebugFiberInDEV
Fixes #18178 (comment).
In 16.13, we added a new warning:
Cannot update a component from inside a body of a function component
. But as we see from reports like #18178 (comment), it fired for updates from inside of class lifecycles too. While arguably these are real issues (they happen in render phase) it's pretty noisy for legacy code.In this PR, I do the following:
from inside a body of a function component
->while rendering
). This more accurately describes when it would fire.render
lifecycles. Everything else will get muted. This is consistent with how our existing class "setState from another component's render" warning works.getDerivedStateFromProps
,shouldComponentUpdate
, andconstructor
. Maybe in strict mode only. However, we should keep them muted forcomponentWill*
lifecycles including render phase ones.Here is a table of the changes:
Red means new behavior, blue means revert to 16.12 behavior.