Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion packages/gatsby/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
},
"peerDependencies": {
"gatsby": "^3.0.0 || ^4.0.0 || ^5.0.0",
"react": "16.x || 17.x || 18.x"
"react": "17.x || 18.x"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q: what about 19?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair, I'll add it in a follow up

},
"devDependencies": {
"@testing-library/react": "^15.0.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@sentry/conventions": "^0.16.0"
},
"peerDependencies": {
"react": "^16.14.0 || 17.x || 18.x || 19.x"
"react": "17.x || 18.x || 19.x"
},
"devDependencies": {
"@testing-library/react": "^15.0.5",
Expand Down
16 changes: 3 additions & 13 deletions packages/react/src/error.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
import { captureException } from '@sentry/browser';
import { isError } from '@sentry/core/browser';
import type { ErrorInfo } from 'react';
import { version } from 'react';

/**
* See if React major version is 17+ by parsing version string.
*/
export function isAtLeastReact17(reactVersion: string): boolean {
const reactMajor = reactVersion.match(/^([^.]+)/);
return reactMajor !== null && parseInt(reactMajor[0]) >= 17;
}

/**
* Recurse through `error.cause` chain to set cause on an error.
Expand Down Expand Up @@ -47,15 +38,14 @@ export function captureReactException(
{ componentStack }: ErrorInfo,
hint?: Parameters<typeof captureException>[1],
): string {
// If on React version >= 17, create stack trace from componentStack param and links
// to to the original error using `error.cause` otherwise relies on error param for stacktrace.
// Linking errors requires the `LinkedErrors` integration be enabled.
// Create a stack trace from the componentStack param and link it to the original error
// using `error.cause`. Linking errors requires the `LinkedErrors` integration be enabled.
// See: https://reactjs.org/blog/2020/08/10/react-v17-rc.html#native-component-stacks
//
// Although `componentDidCatch` is typed to accept an `Error` object, it can also be invoked
// with non-error objects. This is why we need to check if the error is an error-like object.
// See: https://github.com/getsentry/sentry-javascript/issues/6167
if (isAtLeastReact17(version) && isError(error) && componentStack) {
if (isError(error) && componentStack) {
const errorBoundaryError = new Error(error.message);
errorBoundaryError.name = `React ErrorBoundary ${error.name}`;
errorBoundaryError.stack = componentStack;
Expand Down
15 changes: 0 additions & 15 deletions packages/react/src/hoist-non-react-statics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,6 @@ const MEMO_STATICS = {
const ForwardRefType = Symbol.for('react.forward_ref');
const MemoType = Symbol.for('react.memo');

/**
* Check if a component is a Memo component
*/
function isMemo(component: unknown): boolean {
return (
typeof component === 'object' && component !== null && (component as { $$typeof?: symbol }).$$typeof === MemoType
);
}

/**
* Map of React component types to their specific statics
*/
Expand All @@ -89,12 +80,6 @@ TYPE_STATICS[MemoType] = MEMO_STATICS;
* Get the appropriate statics object for a given component
*/
function getStatics(component: React.ComponentType<unknown>): Record<string, boolean> {
// React v16.11 and below
if (isMemo(component)) {
return MEMO_STATICS;
}

// React v16.12 and above
const componentType = (component as { $$typeof?: symbol }).$$typeof;
return (componentType && TYPE_STATICS[componentType]) || REACT_STATICS;
}
Expand Down
1 change: 0 additions & 1 deletion packages/react/src/profiler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ function withProfiler<P extends Record<string, any>>(
*
* `useProfiler` is a React hook that profiles a React component.
*
* Requires React 16.8 or above.
* @param name displayName of component being profiled
*/
function useProfiler(
Expand Down
17 changes: 2 additions & 15 deletions packages/react/test/error.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
import * as SentryBrowser from '@sentry/browser';
import { beforeEach, describe, expect, it, test, vi } from 'vitest';
import { isAtLeastReact17, reactErrorHandler } from '../src/error';

describe('isAtLeastReact17', () => {
test.each([
['React 16', '16.0.4', false],
['React 17', '17.0.0', true],
['React 17 with no patch', '17.4', true],
['React 17 with no patch and no minor', '17', true],
['React 18', '18.1.0', true],
['React 19', '19.0.0', true],
])('%s', (_: string, input: string, output: ReturnType<typeof isAtLeastReact17>) => {
expect(isAtLeastReact17(input)).toBe(output);
});
});
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { reactErrorHandler } from '../src/error';

describe('reactErrorHandler', () => {
const captureException = vi.spyOn(SentryBrowser, 'captureException');
Expand Down
Loading