Skip to content

Commit a0033da

Browse files
AbhiPrasadandreiborzavivianyentran
authored
feat: Add errorboundary changes to v8 migration guide (#10455)
Co-authored-by: Andrei <[email protected]> Co-authored-by: vivianyentran <[email protected]>
1 parent c2687b7 commit a0033da

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

platform-includes/migration/javascript-v8/important-changes/javascript.gatsby.mdx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@ If you need to support older versions of React, please use Sentry Gatsby SDK `7.
66

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

9+
### Updated error types to be `unknown` instead of `Error`
10+
11+
In v8, we are changing the `ErrorBoundary` error types returned from `onError`, `onReset`, `onUnmount`, and
12+
`beforeCapture` to be `unknown` instead of `Error`. This more accurately matches the behavior of `componentDidCatch`, which is the
13+
lifecycle method Sentry's `ErrorBoundary` component uses.
14+
15+
As per the [React docs on error boundaries](https://react.dev/reference/react/Component#componentdidcatch):
16+
17+
> error: The `error` that was thrown. In practice, it will usually be an instance of `Error` but this is not guaranteed
18+
> because JavaScript allows to throw any value, including strings or even `null`.
19+
20+
This means you will have to use `instanceof Error` or similar to explicitly make sure that the error thrown was an
21+
instance of `Error`.
22+
23+
The Sentry SDK maintainers also went ahead and made a PR to update the
24+
[TypeScript definitions of `componentDidCatch`](https://github.com/DefinitelyTyped/DefinitelyTyped/pull/69434) for the
25+
React package. This will be released with React 20.
26+
927
### Removal of Gatsby Initialization via plugin options
1028

1129
In `8.x`, we are removing the ability to initialize the Gatsby SDK via plugin options.

platform-includes/migration/javascript-v8/important-changes/javascript.react.mdx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,21 @@ Sentry React SDK `8.x` supports React version `16.0.0` or higher.
55
If you need to support older versions of React, please use Sentry Next.js SDK `7.x`.
66

77
<Include name="migration/javascript-v8/compatible-browsers" />
8+
9+
### Updated error types to be `unknown` instead of `Error`
10+
11+
In v8, we are changing the `ErrorBoundary` error types returned from `onError`, `onReset`, `onUnmount`, and
12+
`beforeCapture` to be `unknown` instead of `Error`. This more accurately matches the behavior of `componentDidCatch`, which is the
13+
lifecycle method Sentry's `ErrorBoundary` component uses.
14+
15+
As per the [React docs on error boundaries](https://react.dev/reference/react/Component#componentdidcatch):
16+
17+
> error: The `error` that was thrown. In practice, it will usually be an instance of `Error` but this is not guaranteed
18+
> because JavaScript allows to throw any value, including strings or even `null`.
19+
20+
This means you will have to use `instanceof Error` or similar to explicitly make sure that the error thrown was an
21+
instance of `Error`.
22+
23+
The Sentry SDK maintainers also went ahead and made a PR to update the
24+
[TypeScript definitions of `componentDidCatch`](https://github.com/DefinitelyTyped/DefinitelyTyped/pull/69434) for the
25+
React package. This will be released with React 20.

0 commit comments

Comments
 (0)