Skip to content
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

React component render error inside ErrorBoundary captured twice #1432

Closed
bourds opened this issue Jul 10, 2018 · 2 comments
Closed

React component render error inside ErrorBoundary captured twice #1432

bourds opened this issue Jul 10, 2018 · 2 comments

Comments

@bourds
Copy link

bourds commented Jul 10, 2018

Do you want to request a feature or report a bug?

Report a bug

What is the current behavior?

I'm using raven-js@3.26.3 with React@16.3.2. When I wrap a component that throws an error during render in an ErrorBoundary component that invokes Raven.captureException() I'm actually getting duplicate errors logged (and not combined).

https://repl.it/repls/TotalHandmadeBrowser

My theory is that in react when a unit of work fails it tries to 'replayUnitOfWork' before giving up. This method uses a fake event which I think is triggering the raven-wrapped event listening mechanism which triggers the additional Raven.captureException() call. If I look at that second recorded error the 'mechanism' is as follows:

{
“mechanism”: {
“type”: “instrument”,
“data”: {
“target”: “EventTarget”,
“function”: “addEventListener”,
“handler”: “callCallback”
}
}
}

If I set a breakpoint inside Raven.captureException() I see it is getting invoked twice: once from my ErrorBoundary and once from inside Ravens function wrap for the above mechanism.

What is the expected behavior?
It should only log the captured error once.

I'm using version 3.26.3 of raven-js which I pulled down via NPM. I'm also using the on-premise version of sentry.io.

@kamilogorek
Copy link
Contributor

kamilogorek commented Jul 11, 2018

Hey, it's caused by React bubbling up all the errors from ErrorBoundries to the main onerror handler in development mode. Once you build your app and use production code, it won't report 2 separate events.
Could you give it a try?

@bourds
Copy link
Author

bourds commented Jul 11, 2018

Right you are! Production mode eliminates the dupe.

I also found this interesting (and long) discussion on the topic.

facebook/react#10474

Thanks! I'll close.

@bourds bourds closed this as completed Jul 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants