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, but componentDidCatch 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 .
rendering BuggyCounter. count: 5package.json and change the react version from 16.12.0 to 16.0.0.The error is being thrown twice and componentDidCatch is running only once.
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.
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.
https://github.com/facebook/react/blob/c55c34e46a6d8148afb78594d14f4675f9346900/packages/shared/ReactFeatureFlags.js#L16-L18
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
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!
Most helpful comment
This is an intentional behavior in DEV.
https://github.com/facebook/react/blob/c55c34e46a6d8148afb78594d14f4675f9346900/packages/shared/ReactFeatureFlags.js#L16-L18