-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
Error boundary seems to be failing to catch errors. #15571
Comments
I get the same problem |
I had the same issue. Looking for any suggestion. |
Same for me. |
Same for me here. |
I don't think |
This requires React 16.0.0-beta.5 |
@eliperkins My component still doesn't catch an error. RN: 0.49.3 |
@JesperLekland Can you show your component? Note that only errors thrown within React lifecycle events will be captured. |
I also have this issue. I was just testing this by throwing an error in the |
I can reproduce with
|
So is the "bug" here that the RedBox is displayed? It seems like if the error is caught and handled, there shouldn't be a RedBox, but I don't think that matches that the original issue was here... |
That's all I'm seeing, at least. Happy to open a new issue if you'd prefer. |
Here's the demo using expo SDK 22, which uses react 16.0.0-beta.5 and react-native 0.49: Result: |
@gunn Try this example https://snack.expo.io/@gusgard/error-boundaries-(componentdidcatch-example) Remember that errors are caught in render but are not caught in event handlers. If you test it in release mode, you will see the message "Error in Component", otherwise in dev mode on your device (without using Expo) tap dismiss in the error screen. |
I am having the same issue.
|
@gusgard I believe it should handle errors in any component lifecycle methods, not just render: https://codepen.io/anon/pen/eePzKX |
@bvaughn Would you happen to know if the RN renderer is calling console.error() at error boundaries? This would explain the redbox in dev and crash in prod (which is what console.error does). |
Yes, |
Thanks for the pointer, looks like we can override this with the injection interface. |
I'm sorry, @ides. I believe my previous message was misleading. (It's been a while since I've worked with this code.)
So it's still possible that |
Actually, it looks like this call to |
Same for me.
|
the issue is that
or
hope that helps |
Cole's right. I didn't read the original bug report until now, but it's describing expected behavior. From the React docs:
|
This is still happening for us we are throwing from render and/or componentDidMount To clarify. By "This" I mean that the red screen shows and the release build crashes, even though the componentDidCatch does actually run Example: https://snack.expo.io/HJ4riE2ZG |
@apolishch |
I'm attempting to create a 'fail whale' page that pops up whenever the app crashes. No matter what it is throwing a red screen. Here is a snack I made with the same issues: What am I doing wrong here? Thanks! |
@judgejab your code looks fine. What happens when you dismiss the red screen. In dev red screen still shows, just dismiss. Run in release mode and it won't show red screen |
@stantoncbradley When I dismiss the red screen, I just get a fixed blank white screen. In release mode the app just crashes. |
@judgejab hmm code looks fine to me. What react/react native versions? |
I can't get this to work properly either. If I just run a test as @succeed2011 shows, it works, but if an error is thrown down the road somehwere in my real life app, the error isn't caught. |
I found out why I couldn't catch deeper down errors. There was a bug in |
@MrLoh Can you please post the package.json file that works for you? |
I think it only works in production or staging environments I just catches erros in lyfecycle and render, not in other global js code. For that use this: if (!__DEV__) {
global.ErrorUtils.setGlobalHandler((error: Error, isFatal: boolean) => {
// report the error that occurred and raise a modal if it was fatal
reportError(error);
if (isFatal) showErrorAlert(error);
});
} |
I also have problems with this. |
As the docs mention, |
@Spenhouet you can’t catch those errors in a component, you have to use the global catching code I posted above. |
I also face to redbox with I can continue to work dismissing redbox but I'd like to suppress it when developing error handler. My react-native version is v0.57.3 |
Me too. show the redbox error, show componentDidCatch alert in my code. |
I have almost given up on ErrorBoundaries, they just don't work as described, (either that or the documentation needs seriously updating). Even the simplest examples, (including the docs) don't work. I feel perhaps the ErrorBoundary ecosystem in React is not yet fully mature? Unless I am way off base, the following example doesn't work (React 16.6).
even using the suggested Is it me, or.... ? |
@stevematdavies Yes I think you have misunderstood a little. Try it like this: class Child extends React.Component {
componentDidMount() {
throw new Error("BOOM")
}
render() {
return (
<h1>Im the Wrapped component with a Bug</h1>
)
}
}
class WrappedChild extends React.Component {
render() {
return (
<ErrorBoundary>
<Child/>
</ErrorBoundary>
)
}
} |
Aha I see, yes then it was my misunderstanding, although, I still hold the docs could do with some refinement. So wrapped component must be an Element itself that throws, one can't simply wrap html from within an element. Many thanks @gunn much appreciated. |
I also see the red screen on expo dev mode. On production mode the app restart first and then it shows the error. "react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz", |
There is no issue here to my understanding this is the expected behavior:
I think the idea here is that in debug mode you want to know of any exception that is being thrown - even if caught, we can argue if this is a good approach or not but I don't think this is a bug. |
My current experience is as follows:
|
RN 0.59.8 works well by showing alternative view on dismiss error |
https://github.com/doochik/babel-plugin-transform-react-ssr-try-catch I use that Babel plugin, basically it's to wrap render() method in React.Component with try-catch statement. |
The behaviour in the code posted by the OP seems correct and different from the issues in the replies. The error is thrown in |
Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions. |
Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information. |
Environment
Target Platform:
iOS, android
Build tools:
create-react-native-app / expo locally, snack.expo.io online.
Steps to Reproduce
Use this code:
Expected Behavior
It should behave like react in the browser and display the text "Error in Component".
Actual Behavior
In development mode the red error screen shows. In production the app crashes and restarts.
Reproducible Demo
https://snack.expo.io/ryHYYfPdZ
The text was updated successfully, but these errors were encountered: