-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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
componentDidCatch doesn't catch some invariants #13820
Comments
Hi, I would like to give a try to this issue ! |
I also would like to know where to take a look :) |
Humm, that is weird. When I tried the codesandbox example on a Windows a few hours earlier, I was able to reproduce the issue. Edit : just tested back on my Windows PC, same behavior for both Components... 🤔 |
This may also be expected behavior, it is in the error boundary. https://reactjs.org/docs/error-boundaries.html Here's the same example where comp2 is pass in as a child of the ErrorBoundary. https://codesandbox.io/s/pj6oz1xk60 However with that being said, it is odd that one error is caught while the other is not. |
You used react 16.4. As i wrote, the problem appeared in 16.5 (and it's still there in 16.6). Moreover, you should put this.props.children instead of Comp1 in line 19 of your example. When you do this, the behavior will be exactly as described in the first post. |
I've reproduced this problem separately: https://codesandbox.io/s/8npm2jq05l Here are my findings:
See the comments in the code for a few different ways to cause the error boundary to successfully trigger. |
Do you want to request a feature or report a bug?
A bug.
What is the current behavior?
componentDidCatch isn't called when a child component renders a void element containing another element. The app just crashes.
If it contains just text, the same error ("...is a void element tag and must neither have children nor use dangerouslySetInnerHTML") appears, but this time with componentDidCatch properly called.
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:
https://codesandbox.io/s/0042z5wrlp
The behavior is different when you change Comp1 with Comp2.
What is the expected behavior?
componentDidCatch should be called in both cases.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
16.5.2.
In 16.4.2 it worked correctly.
The text was updated successfully, but these errors were encountered: