|
1 | 1 | import { captureException } from '@sentry/browser'; |
2 | 2 | import { isError } from '@sentry/core/browser'; |
3 | 3 | import type { ErrorInfo } from 'react'; |
4 | | -import { version } from 'react'; |
5 | | - |
6 | | -/** |
7 | | - * See if React major version is 17+ by parsing version string. |
8 | | - */ |
9 | | -export function isAtLeastReact17(reactVersion: string): boolean { |
10 | | - const reactMajor = reactVersion.match(/^([^.]+)/); |
11 | | - return reactMajor !== null && parseInt(reactMajor[0]) >= 17; |
12 | | -} |
13 | 4 |
|
14 | 5 | /** |
15 | 6 | * Recurse through `error.cause` chain to set cause on an error. |
@@ -47,15 +38,14 @@ export function captureReactException( |
47 | 38 | { componentStack }: ErrorInfo, |
48 | 39 | hint?: Parameters<typeof captureException>[1], |
49 | 40 | ): string { |
50 | | - // If on React version >= 17, create stack trace from componentStack param and links |
51 | | - // to to the original error using `error.cause` otherwise relies on error param for stacktrace. |
52 | | - // Linking errors requires the `LinkedErrors` integration be enabled. |
| 41 | + // Create a stack trace from the componentStack param and link it to the original error |
| 42 | + // using `error.cause`. Linking errors requires the `LinkedErrors` integration be enabled. |
53 | 43 | // See: https://reactjs.org/blog/2020/08/10/react-v17-rc.html#native-component-stacks |
54 | 44 | // |
55 | 45 | // Although `componentDidCatch` is typed to accept an `Error` object, it can also be invoked |
56 | 46 | // with non-error objects. This is why we need to check if the error is an error-like object. |
57 | 47 | // See: https://github.com/getsentry/sentry-javascript/issues/6167 |
58 | | - if (isAtLeastReact17(version) && isError(error) && componentStack) { |
| 48 | + if (isError(error) && componentStack) { |
59 | 49 | const errorBoundaryError = new Error(error.message); |
60 | 50 | errorBoundaryError.name = `React ErrorBoundary ${error.name}`; |
61 | 51 | errorBoundaryError.stack = componentStack; |
|
0 commit comments