ref(react): Rely on error.cause to link ErrorBoundary errors #4005
+37
−97
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
React Error Boundaries rely on the
componentDidCatch
lifecycle hook to catch errors that occur inside React components. They are typed like so:In React 17, the componentStack property of error info was changed to be more similar to an actual stack trace. This meant we could parse the
componentStack
as an exception and ingest it into Sentry. We ended up doing this. See #3532 for more details.The way we did this is by creating two events, one from the original error, and one from the
componentStack
from React's error info. We then merged them together like so:This PR refactors this merging of two events, by getting rid of the
captureEvent
entirely in favour of just usingcaptureException
. We do this by taking advantage oferror.cause
, which should link the errors using ourLinkedErrors
integration. If a user doesn't want this behaviour to happen, they can strip theerror.cause
property using thebeforeCapture
option. In addition, if the user hasLinkedErrors
configured differently, they can updateerror.cause
to whatever they want (they have full access withbeforeCapture
).By moving to
captureException
, we also preserve the event hint, which should fix #3987.Will open up a docs update after this PR is merged.