From caebf119c8367daf32f77cb680f9a42e6d40abaa Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Thu, 30 Jan 2025 15:48:12 -0800 Subject: [PATCH 1/5] fix default import --- packages/react/src/profiler.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/react/src/profiler.tsx b/packages/react/src/profiler.tsx index 2a147541b4b2..0d5c40263298 100644 --- a/packages/react/src/profiler.tsx +++ b/packages/react/src/profiler.tsx @@ -1,9 +1,13 @@ import { startInactiveSpan } from '@sentry/browser'; import type { Span } from '@sentry/core'; import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, spanToJSON, timestampInSeconds, withActiveSpan } from '@sentry/core'; -import hoistNonReactStatics from 'hoist-non-react-statics'; +import * as hoistNonReactStatics from 'hoist-non-react-statics'; import * as React from 'react'; +// Ensure we use the default export from hoist-non-react-statics if available, +// falling back to the module itself. This handles both ESM and CJS usage. +const hoistStatics: typeof hoistNonReactStatics.default = hoistNonReactStatics.default || hoistNonReactStatics; + import { REACT_MOUNT_OP, REACT_RENDER_OP, REACT_UPDATE_OP } from './constants'; export const UNKNOWN_COMPONENT = 'unknown'; @@ -170,7 +174,7 @@ function withProfiler

>( // Copy over static methods from Wrapped component to Profiler HOC // See: https://reactjs.org/docs/higher-order-components.html#static-methods-must-be-copied-over - hoistNonReactStatics(Wrapped, WrappedComponent); + hoistStatics(Wrapped, WrappedComponent); return Wrapped; } @@ -236,4 +240,4 @@ function useProfiler( }, []); } -export { withProfiler, Profiler, useProfiler }; +export { Profiler, useProfiler, withProfiler }; From 481520fbc2a102c4639ffee5e288bcfc4664f19b Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Thu, 30 Jan 2025 15:53:05 -0800 Subject: [PATCH 2/5] fix all imports for hoistNonReactStatics --- packages/react/src/errorboundary.tsx | 2 +- packages/react/src/hoist-non-react-statics.ts | 5 +++++ packages/react/src/profiler.tsx | 9 +++------ packages/react/src/reactrouter.tsx | 2 +- packages/react/src/reactrouterv6-compat-utils.tsx | 2 +- 5 files changed, 11 insertions(+), 9 deletions(-) create mode 100644 packages/react/src/hoist-non-react-statics.ts diff --git a/packages/react/src/errorboundary.tsx b/packages/react/src/errorboundary.tsx index 9925ef1a8308..ec0ab5874576 100644 --- a/packages/react/src/errorboundary.tsx +++ b/packages/react/src/errorboundary.tsx @@ -2,7 +2,7 @@ import type { ReportDialogOptions } from '@sentry/browser'; import { getClient, showReportDialog, withScope } from '@sentry/browser'; import { logger } from '@sentry/core'; import type { Scope } from '@sentry/core'; -import hoistNonReactStatics from 'hoist-non-react-statics'; +import { hoistNonReactStatics } from './hoist-non-react-statics'; import * as React from 'react'; import { DEBUG_BUILD } from './debug-build'; diff --git a/packages/react/src/hoist-non-react-statics.ts b/packages/react/src/hoist-non-react-statics.ts new file mode 100644 index 000000000000..970928c80d23 --- /dev/null +++ b/packages/react/src/hoist-non-react-statics.ts @@ -0,0 +1,5 @@ +import * as hoistNonReactStaticsImport from 'hoist-non-react-statics'; + +// Ensure we use the default export from hoist-non-react-statics if available, +// falling back to the module itself. This handles both ESM and CJS usage. +export const hoistNonReactStatics = hoistNonReactStaticsImport.default || hoistNonReactStaticsImport; diff --git a/packages/react/src/profiler.tsx b/packages/react/src/profiler.tsx index 0d5c40263298..c7ac2145a961 100644 --- a/packages/react/src/profiler.tsx +++ b/packages/react/src/profiler.tsx @@ -1,14 +1,11 @@ import { startInactiveSpan } from '@sentry/browser'; import type { Span } from '@sentry/core'; import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, spanToJSON, timestampInSeconds, withActiveSpan } from '@sentry/core'; -import * as hoistNonReactStatics from 'hoist-non-react-statics'; -import * as React from 'react'; -// Ensure we use the default export from hoist-non-react-statics if available, -// falling back to the module itself. This handles both ESM and CJS usage. -const hoistStatics: typeof hoistNonReactStatics.default = hoistNonReactStatics.default || hoistNonReactStatics; +import * as React from 'react'; import { REACT_MOUNT_OP, REACT_RENDER_OP, REACT_UPDATE_OP } from './constants'; +import { hoistNonReactStatics } from './hoist-non-react-statics'; export const UNKNOWN_COMPONENT = 'unknown'; @@ -174,7 +171,7 @@ function withProfiler

>( // Copy over static methods from Wrapped component to Profiler HOC // See: https://reactjs.org/docs/higher-order-components.html#static-methods-must-be-copied-over - hoistStatics(Wrapped, WrappedComponent); + hoistNonReactStatics(Wrapped, WrappedComponent); return Wrapped; } diff --git a/packages/react/src/reactrouter.tsx b/packages/react/src/reactrouter.tsx index 42acef91522b..a841879e0770 100644 --- a/packages/react/src/reactrouter.tsx +++ b/packages/react/src/reactrouter.tsx @@ -14,7 +14,7 @@ import { spanToJSON, } from '@sentry/core'; import type { Client, Integration, Span, TransactionSource } from '@sentry/core'; -import hoistNonReactStatics from 'hoist-non-react-statics'; +import { hoistNonReactStatics } from './hoist-non-react-statics'; import * as React from 'react'; import type { ReactElement } from 'react'; diff --git a/packages/react/src/reactrouterv6-compat-utils.tsx b/packages/react/src/reactrouterv6-compat-utils.tsx index db65c32cee99..f1f7c83af77c 100644 --- a/packages/react/src/reactrouterv6-compat-utils.tsx +++ b/packages/react/src/reactrouterv6-compat-utils.tsx @@ -22,7 +22,7 @@ import { } from '@sentry/core'; import * as React from 'react'; -import hoistNonReactStatics from 'hoist-non-react-statics'; +import { hoistNonReactStatics } from './hoist-non-react-statics'; import { DEBUG_BUILD } from './debug-build'; import type { Action, From 3539d9564320e222a4c7e0ede9262dcaf13a11a3 Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Thu, 30 Jan 2025 16:03:25 -0800 Subject: [PATCH 3/5] format Co-authored-by: Catherine Lee <55311782+c298lee@users.noreply.github.com> --- packages/react/src/profiler.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/react/src/profiler.tsx b/packages/react/src/profiler.tsx index c7ac2145a961..d7478ce6fb33 100644 --- a/packages/react/src/profiler.tsx +++ b/packages/react/src/profiler.tsx @@ -1,7 +1,6 @@ import { startInactiveSpan } from '@sentry/browser'; import type { Span } from '@sentry/core'; import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, spanToJSON, timestampInSeconds, withActiveSpan } from '@sentry/core'; - import * as React from 'react'; import { REACT_MOUNT_OP, REACT_RENDER_OP, REACT_UPDATE_OP } from './constants'; From c2b81ecaa98510c475354d970adf860589759862 Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Thu, 30 Jan 2025 16:17:31 -0800 Subject: [PATCH 4/5] biome --- packages/react/src/errorboundary.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react/src/errorboundary.tsx b/packages/react/src/errorboundary.tsx index ec0ab5874576..97f89357f38d 100644 --- a/packages/react/src/errorboundary.tsx +++ b/packages/react/src/errorboundary.tsx @@ -2,8 +2,8 @@ import type { ReportDialogOptions } from '@sentry/browser'; import { getClient, showReportDialog, withScope } from '@sentry/browser'; import { logger } from '@sentry/core'; import type { Scope } from '@sentry/core'; -import { hoistNonReactStatics } from './hoist-non-react-statics'; import * as React from 'react'; +import { hoistNonReactStatics } from './hoist-non-react-statics'; import { DEBUG_BUILD } from './debug-build'; import { captureReactException } from './error'; From 147f60762bad4037f850f978af44c2bbf38cbe38 Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Thu, 30 Jan 2025 16:25:14 -0800 Subject: [PATCH 5/5] mas biome --- packages/react/src/reactrouter.tsx | 2 +- packages/react/src/reactrouterv6-compat-utils.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/react/src/reactrouter.tsx b/packages/react/src/reactrouter.tsx index a841879e0770..2692659de6c4 100644 --- a/packages/react/src/reactrouter.tsx +++ b/packages/react/src/reactrouter.tsx @@ -14,9 +14,9 @@ import { spanToJSON, } from '@sentry/core'; import type { Client, Integration, Span, TransactionSource } from '@sentry/core'; -import { hoistNonReactStatics } from './hoist-non-react-statics'; import * as React from 'react'; import type { ReactElement } from 'react'; +import { hoistNonReactStatics } from './hoist-non-react-statics'; import type { Action, Location } from './types'; diff --git a/packages/react/src/reactrouterv6-compat-utils.tsx b/packages/react/src/reactrouterv6-compat-utils.tsx index f1f7c83af77c..f9cf76cfc498 100644 --- a/packages/react/src/reactrouterv6-compat-utils.tsx +++ b/packages/react/src/reactrouterv6-compat-utils.tsx @@ -22,8 +22,8 @@ import { } from '@sentry/core'; import * as React from 'react'; -import { hoistNonReactStatics } from './hoist-non-react-statics'; import { DEBUG_BUILD } from './debug-build'; +import { hoistNonReactStatics } from './hoist-non-react-statics'; import type { Action, AgnosticDataRouteMatch,