From 25e70715b7f13245a0548f32ef379f27c0613c53 Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Fri, 31 Jan 2025 00:30:45 -0800 Subject: [PATCH] fix(react): Import default for hoistNonReactStatics (#15238) --- packages/react/src/errorboundary.tsx | 2 +- packages/react/src/hoist-non-react-statics.ts | 5 +++++ packages/react/src/profiler.tsx | 4 ++-- packages/react/src/reactrouter.tsx | 2 +- packages/react/src/reactrouterv6-compat-utils.tsx | 2 +- 5 files changed, 10 insertions(+), 5 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..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'; 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 2a147541b4b2..d7478ce6fb33 100644 --- a/packages/react/src/profiler.tsx +++ b/packages/react/src/profiler.tsx @@ -1,10 +1,10 @@ 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 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'; @@ -236,4 +236,4 @@ function useProfiler( }, []); } -export { withProfiler, Profiler, useProfiler }; +export { Profiler, useProfiler, withProfiler }; diff --git a/packages/react/src/reactrouter.tsx b/packages/react/src/reactrouter.tsx index 42acef91522b..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 db65c32cee99..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,