diff --git a/platform-includes/migration/javascript-v8/important-changes/javascript.gatsby.mdx b/platform-includes/migration/javascript-v8/important-changes/javascript.gatsby.mdx index fc4cc24d015f46..5c317684362d9b 100644 --- a/platform-includes/migration/javascript-v8/important-changes/javascript.gatsby.mdx +++ b/platform-includes/migration/javascript-v8/important-changes/javascript.gatsby.mdx @@ -6,6 +6,24 @@ If you need to support older versions of React, please use Sentry Gatsby SDK `7. +### 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 the behavior of `componentDidCatch`, which is the +lifecycle method Sentry's `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. diff --git a/platform-includes/migration/javascript-v8/important-changes/javascript.react.mdx b/platform-includes/migration/javascript-v8/important-changes/javascript.react.mdx index 9e86ca7640c124..d589ae7ac64713 100644 --- a/platform-includes/migration/javascript-v8/important-changes/javascript.react.mdx +++ b/platform-includes/migration/javascript-v8/important-changes/javascript.react.mdx @@ -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`. + +### 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 the behavior of `componentDidCatch`, which is the +lifecycle method Sentry's `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.