From 315e0110df5dd28e9f5ffae70ea1426a3c4b6781 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Thu, 20 Jun 2024 12:00:53 -0400 Subject: [PATCH 1/3] feat: Add errorboundary changes to v8 migration guide --- .../important-changes/javascript.gatsby.mdx | 18 ++++++++++++++++++ .../important-changes/javascript.react.mdx | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) 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..3a9d4f83dfdac1 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 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. 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..7ec811b3577274 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 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. From 5e9256d4489ae68993dcd5b303bfcffc107ddee4 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Thu, 20 Jun 2024 15:12:10 -0400 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Andrei <168741329+andreiborza@users.noreply.github.com> --- .../javascript-v8/important-changes/javascript.gatsby.mdx | 2 +- .../javascript-v8/important-changes/javascript.react.mdx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 3a9d4f83dfdac1..03492c9b57a038 100644 --- a/platform-includes/migration/javascript-v8/important-changes/javascript.gatsby.mdx +++ b/platform-includes/migration/javascript-v8/important-changes/javascript.gatsby.mdx @@ -9,7 +9,7 @@ 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 behaviour of `componentDidCatch`, the +`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): 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 7ec811b3577274..7f573337be770e 100644 --- a/platform-includes/migration/javascript-v8/important-changes/javascript.react.mdx +++ b/platform-includes/migration/javascript-v8/important-changes/javascript.react.mdx @@ -9,7 +9,7 @@ If you need to support older versions of React, please use Sentry Next.js 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 behaviour of `componentDidCatch`, the +`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): From aeceebccf6cf32e6acd949a9785675ab80056776 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Thu, 20 Jun 2024 19:37:21 -0400 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: vivianyentran <20403606+vivianyentran@users.noreply.github.com> --- .../javascript-v8/important-changes/javascript.gatsby.mdx | 8 ++++---- .../javascript-v8/important-changes/javascript.react.mdx | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) 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 03492c9b57a038..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,11 +6,11 @@ If you need to support older versions of React, please use Sentry Gatsby SDK `7. -### Updated error types to be `unknown` instead of `Error`. +### 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. +`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): @@ -22,7 +22,7 @@ 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. +React package. This will be released with React 20. ### Removal of Gatsby Initialization 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 7f573337be770e..d589ae7ac64713 100644 --- a/platform-includes/migration/javascript-v8/important-changes/javascript.react.mdx +++ b/platform-includes/migration/javascript-v8/important-changes/javascript.react.mdx @@ -6,11 +6,11 @@ If you need to support older versions of React, please use Sentry Next.js SDK `7 -### Updated error types to be `unknown` instead of `Error`. +### 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. +`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): @@ -22,4 +22,4 @@ 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. +React package. This will be released with React 20.