Skip to content

feat: Add errorboundary changes to v8 migration guide #10455

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

Merged
merged 3 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ If you need to support older versions of React, please use Sentry Gatsby SDK `7.

<Include name="migration/javascript-v8/compatible-browsers" />

### Updated error types to be `unknown` instead of `Error`.

In v8, we are changing the `ErrorBoundary` error types returned from `onError`, `onReset`, `onUnmount`, and
`beforeCapture` to be `unknown` instead of `Error`. This more accurately matches behaviour of `componentDidCatch`, the
lifecycle method the Sentry `ErrorBoundary` component uses.

As per the [React docs on error boundaries](https://react.dev/reference/react/Component#componentdidcatch):

> error: The `error` that was thrown. In practice, it will usually be an instance of `Error` but this is not guaranteed
> because JavaScript allows to throw any value, including strings or even `null`.

This means you will have to use `instanceof Error` or similar to explicitly make sure that the error thrown was an
instance of `Error`.

The Sentry SDK maintainers also went ahead and made a PR to update the
[TypeScript definitions of `componentDidCatch`](https://github.com/DefinitelyTyped/DefinitelyTyped/pull/69434) for the
React package - this will be released with React 20.

### Removal of Gatsby Initialization via plugin options

In `8.x`, we are removing the ability to initialize the Gatsby SDK via plugin options.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,21 @@ Sentry React SDK `8.x` supports React version `16.0.0` or higher.
If you need to support older versions of React, please use Sentry Next.js SDK `7.x`.

<Include name="migration/javascript-v8/compatible-browsers" />

### Updated error types to be `unknown` instead of `Error`.

In v8, we are changing the `ErrorBoundary` error types returned from `onError`, `onReset`, `onUnmount`, and
`beforeCapture` to be `unknown` instead of `Error`. This more accurately matches behaviour of `componentDidCatch`, the
lifecycle method the Sentry `ErrorBoundary` component uses.

As per the [React docs on error boundaries](https://react.dev/reference/react/Component#componentdidcatch):

> error: The `error` that was thrown. In practice, it will usually be an instance of `Error` but this is not guaranteed
> because JavaScript allows to throw any value, including strings or even `null`.

This means you will have to use `instanceof Error` or similar to explicitly make sure that the error thrown was an
instance of `Error`.

The Sentry SDK maintainers also went ahead and made a PR to update the
[TypeScript definitions of `componentDidCatch`](https://github.com/DefinitelyTyped/DefinitelyTyped/pull/69434) for the
React package - this will be released with React 20.
Loading