-
Notifications
You must be signed in to change notification settings - Fork 45.6k
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
Bug: When throwing an error on component render, the component rerenders and throws twice, but componentDidCatch runs only once. #17966
Comments
It seems this issue was introduced in 16.3 |
If the error is thrown from componentDidUpdate instead of render, then the component is not rendered an "extra" time. |
This is an intentional behavior in DEV. react/packages/shared/ReactFeatureFlags.js Lines 16 to 18 in c55c34e
|
Hi guys, i tried to replicate this issue and I discovered that its the react-dom version that's the cause. When i change the react-dom version to "16.0 - 16.2", the error is thrown only once, but from react-dom version "16.3" and above, its thrown twice. How can one go about fixing this |
It seems the best you can do is to close the error screen when it pops up, and you will see the result of componentDidCatch. |
Hi @ayershov777 so i just tried that and it just displayed "Error" on the screen |
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment! |
This question on stack overflow was made and while trying to solve it, I realized something.
I found out that on version
16.12.0
of react, when you throw an error on the render method, it render and throws the error twice, butcomponentDidCatch
runs only once.I version
16.0.0
it throws the error only once.React version:
16.0.0
throws the error only once.16.12.0
throws the error twice .Steps To Reproduce
rendering BuggyCounter. count: 5
package.json
and change the react version from16.12.0
to16.0.0
.The current behavior
The error is being thrown twice and
componentDidCatch
is running only once.The expected behavior
The error should be thrown only once or
componentDidCatch
should run the number of times an error is thrown.I'm not sure if it's intended to be or if it's a new thing that changed in the newer version, if that is the case, please let me know.
The text was updated successfully, but these errors were encountered: