@sentry/react 7.90.0 → 7.92.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/constants.js.map +1 -1
- package/cjs/debug-build.js.map +1 -1
- package/cjs/errorboundary.js +3 -2
- package/cjs/errorboundary.js.map +1 -1
- package/cjs/profiler.js +10 -5
- package/cjs/profiler.js.map +1 -1
- package/cjs/reactrouter.js +4 -3
- package/cjs/reactrouter.js.map +1 -1
- package/cjs/reactrouterv3.js +1 -1
- package/cjs/reactrouterv3.js.map +1 -1
- package/cjs/reactrouterv6.js +6 -4
- package/cjs/reactrouterv6.js.map +1 -1
- package/cjs/redux.js.map +1 -1
- package/cjs/sdk.js.map +1 -1
- package/esm/constants.js.map +1 -1
- package/esm/debug-build.js.map +1 -1
- package/esm/errorboundary.js +3 -2
- package/esm/errorboundary.js.map +1 -1
- package/esm/profiler.js +10 -5
- package/esm/profiler.js.map +1 -1
- package/esm/reactrouter.js +4 -3
- package/esm/reactrouter.js.map +1 -1
- package/esm/reactrouterv3.js +1 -1
- package/esm/reactrouterv3.js.map +1 -1
- package/esm/reactrouterv6.js +6 -4
- package/esm/reactrouterv6.js.map +1 -1
- package/esm/redux.js.map +1 -1
- package/esm/sdk.js.map +1 -1
- package/package.json +10 -4
- package/types/errorboundary.d.ts +1 -1
- package/types/errorboundary.d.ts.map +1 -1
- package/types/profiler.d.ts.map +1 -1
- package/types/reactrouter.d.ts.map +1 -1
- package/types/reactrouterv6.d.ts.map +1 -1
- package/types-ts3.8/errorboundary.d.ts +1 -1
package/cjs/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sources":["../../src/constants.ts"],"sourcesContent":["export const REACT_RENDER_OP = 'ui.react.render';\n\nexport const REACT_UPDATE_OP = 'ui.react.update';\n\nexport const REACT_MOUNT_OP = 'ui.react.mount';\n"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../../src/constants.ts"],"sourcesContent":["export const REACT_RENDER_OP = 'ui.react.render';\n\nexport const REACT_UPDATE_OP = 'ui.react.update';\n\nexport const REACT_MOUNT_OP = 'ui.react.mount';\n"],"names":[],"mappings":";;AAAO,MAAM,eAAgB,GAAE,kBAAiB;AAChD;AACO,MAAM,eAAgB,GAAE,kBAAiB;AAChD;AACO,MAAM,cAAe,GAAE;;;;;;"}
|
package/cjs/debug-build.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debug-build.js","sources":["../../src/debug-build.ts"],"sourcesContent":["declare const __DEBUG_BUILD__: boolean;\n\n/**\n * This serves as a build time flag that will be true by default, but false in non-debug builds or if users replace `__SENTRY_DEBUG__` in their generated code.\n *\n * ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking.\n */\nexport const DEBUG_BUILD = __DEBUG_BUILD__;\n"],"names":[],"mappings":";;AAEA;AACA;AACA;AACA;AACA;
|
|
1
|
+
{"version":3,"file":"debug-build.js","sources":["../../src/debug-build.ts"],"sourcesContent":["declare const __DEBUG_BUILD__: boolean;\n\n/**\n * This serves as a build time flag that will be true by default, but false in non-debug builds or if users replace `__SENTRY_DEBUG__` in their generated code.\n *\n * ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking.\n */\nexport const DEBUG_BUILD = __DEBUG_BUILD__;\n"],"names":[],"mappings":";;AAEA;AACA;AACA;AACA;AACA;AACO,MAAM,WAAY,IAAE,OAAA,gBAAA,KAAA,WAAA,IAAA,gBAAA;;;;"}
|
package/cjs/errorboundary.js
CHANGED
|
@@ -75,6 +75,7 @@ class ErrorBoundary extends React__namespace.Component {
|
|
|
75
75
|
this._openFallbackReportDialog = false;
|
|
76
76
|
client.on('afterSendEvent', event => {
|
|
77
77
|
if (!event.type && event.event_id === this._lastEventId) {
|
|
78
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
78
79
|
browser.showReportDialog({ ...props.dialogOptions, eventId: this._lastEventId });
|
|
79
80
|
}
|
|
80
81
|
});
|
|
@@ -197,8 +198,8 @@ function withErrorBoundary(
|
|
|
197
198
|
const componentDisplayName = WrappedComponent.displayName || WrappedComponent.name || UNKNOWN_COMPONENT;
|
|
198
199
|
|
|
199
200
|
const Wrapped = (props) => (
|
|
200
|
-
React__namespace.createElement(ErrorBoundary, { ...errorBoundaryOptions, __self: this, __source: {fileName: _jsxFileName, lineNumber:
|
|
201
|
-
, React__namespace.createElement(WrappedComponent, { ...props, __self: this, __source: {fileName: _jsxFileName, lineNumber:
|
|
201
|
+
React__namespace.createElement(ErrorBoundary, { ...errorBoundaryOptions, __self: this, __source: {fileName: _jsxFileName, lineNumber: 238}}
|
|
202
|
+
, React__namespace.createElement(WrappedComponent, { ...props, __self: this, __source: {fileName: _jsxFileName, lineNumber: 239}} )
|
|
202
203
|
)
|
|
203
204
|
);
|
|
204
205
|
|
package/cjs/errorboundary.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errorboundary.js","sources":["../../src/errorboundary.tsx"],"sourcesContent":["import type { ReportDialogOptions, Scope } from '@sentry/browser';\nimport { captureException, getClient, showReportDialog, withScope } from '@sentry/browser';\nimport { isError, logger } from '@sentry/utils';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nimport { DEBUG_BUILD } from './debug-build';\n\nexport function isAtLeastReact17(version: string): boolean {\n const major = version.match(/^([^.]+)/);\n return major !== null && parseInt(major[0]) >= 17;\n}\n\nexport const UNKNOWN_COMPONENT = 'unknown';\n\nexport type FallbackRender = (errorData: {\n error: Error;\n componentStack: string;\n eventId: string;\n resetError(): void;\n}) => React.ReactElement;\n\nexport type ErrorBoundaryProps = {\n children?: React.ReactNode | (() => React.ReactNode);\n /** If a Sentry report dialog should be rendered on error */\n showDialog?: boolean | undefined;\n /**\n * Options to be passed into the Sentry report dialog.\n * No-op if {@link showDialog} is false.\n */\n dialogOptions?: ReportDialogOptions | undefined;\n /**\n * A fallback component that gets rendered when the error boundary encounters an error.\n *\n * Can either provide a React Component, or a function that returns React Component as\n * a valid fallback prop. If a function is provided, the function will be called with\n * the error, the component stack, and an function that resets the error boundary on error.\n *\n */\n fallback?: React.ReactElement | FallbackRender | undefined;\n /** Called when the error boundary encounters an error */\n onError?: ((error: Error, componentStack: string, eventId: string) => void) | undefined;\n /** Called on componentDidMount() */\n onMount?: (() => void) | undefined;\n /** Called if resetError() is called from the fallback render props function */\n onReset?: ((error: Error | null, componentStack: string | null, eventId: string | null) => void) | undefined;\n /** Called on componentWillUnmount() */\n onUnmount?: ((error: Error | null, componentStack: string | null, eventId: string | null) => void) | undefined;\n /** Called before the error is captured by Sentry, allows for you to add tags or context using the scope */\n beforeCapture?: ((scope: Scope, error: Error | null, componentStack: string | null) => void) | undefined;\n};\n\ntype ErrorBoundaryState =\n | {\n componentStack: null;\n error: null;\n eventId: null;\n }\n | {\n componentStack: React.ErrorInfo['componentStack'];\n error: Error;\n eventId: string;\n };\n\nconst INITIAL_STATE = {\n componentStack: null,\n error: null,\n eventId: null,\n};\n\nfunction setCause(error: Error & { cause?: Error }, cause: Error): void {\n const seenErrors = new WeakMap<Error, boolean>();\n\n function recurse(error: Error & { cause?: Error }, cause: Error): void {\n // If we've already seen the error, there is a recursive loop somewhere in the error's\n // cause chain. Let's just bail out then to prevent a stack overflow.\n if (seenErrors.has(error)) {\n return;\n }\n if (error.cause) {\n seenErrors.set(error, true);\n return recurse(error.cause, cause);\n }\n error.cause = cause;\n }\n\n recurse(error, cause);\n}\n\n/**\n * A ErrorBoundary component that logs errors to Sentry. Requires React >= 16.\n * NOTE: If you are a Sentry user, and you are seeing this stack frame, it means the\n * Sentry React SDK ErrorBoundary caught an error invoking your application code. This\n * is expected behavior and NOT indicative of a bug with the Sentry React SDK.\n */\nclass ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> {\n public state: ErrorBoundaryState;\n\n private readonly _openFallbackReportDialog: boolean;\n\n private _lastEventId?: string;\n\n public constructor(props: ErrorBoundaryProps) {\n super(props);\n\n this.state = INITIAL_STATE;\n this._openFallbackReportDialog = true;\n\n const client = getClient();\n if (client && client.on && props.showDialog) {\n this._openFallbackReportDialog = false;\n client.on('afterSendEvent', event => {\n if (!event.type && event.event_id === this._lastEventId) {\n showReportDialog({ ...props.dialogOptions, eventId: this._lastEventId });\n }\n });\n }\n }\n\n public componentDidCatch(error: Error & { cause?: Error }, { componentStack }: React.ErrorInfo): void {\n const { beforeCapture, onError, showDialog, dialogOptions } = this.props;\n withScope(scope => {\n // If on React version >= 17, create stack trace from componentStack param and links\n // to to the original error using `error.cause` otherwise relies on error param for stacktrace.\n // Linking errors requires the `LinkedErrors` integration be enabled.\n // See: https://reactjs.org/blog/2020/08/10/react-v17-rc.html#native-component-stacks\n //\n // Although `componentDidCatch` is typed to accept an `Error` object, it can also be invoked\n // with non-error objects. This is why we need to check if the error is an error-like object.\n // See: https://github.com/getsentry/sentry-javascript/issues/6167\n if (isAtLeastReact17(React.version) && isError(error)) {\n const errorBoundaryError = new Error(error.message);\n errorBoundaryError.name = `React ErrorBoundary ${error.name}`;\n errorBoundaryError.stack = componentStack;\n\n // Using the `LinkedErrors` integration to link the errors together.\n setCause(error, errorBoundaryError);\n }\n\n if (beforeCapture) {\n beforeCapture(scope, error, componentStack);\n }\n\n const eventId = captureException(error, {\n captureContext: {\n contexts: { react: { componentStack } },\n },\n mechanism: { handled: false },\n });\n\n if (onError) {\n onError(error, componentStack, eventId);\n }\n if (showDialog) {\n this._lastEventId = eventId;\n if (this._openFallbackReportDialog) {\n showReportDialog({ ...dialogOptions, eventId });\n }\n }\n\n // componentDidCatch is used over getDerivedStateFromError\n // so that componentStack is accessible through state.\n this.setState({ error, componentStack, eventId });\n });\n }\n\n public componentDidMount(): void {\n const { onMount } = this.props;\n if (onMount) {\n onMount();\n }\n }\n\n public componentWillUnmount(): void {\n const { error, componentStack, eventId } = this.state;\n const { onUnmount } = this.props;\n if (onUnmount) {\n onUnmount(error, componentStack, eventId);\n }\n }\n\n public resetErrorBoundary: () => void = () => {\n const { onReset } = this.props;\n const { error, componentStack, eventId } = this.state;\n if (onReset) {\n onReset(error, componentStack, eventId);\n }\n this.setState(INITIAL_STATE);\n };\n\n public render(): React.ReactNode {\n const { fallback, children } = this.props;\n const state = this.state;\n\n if (state.error) {\n let element: React.ReactElement | undefined = undefined;\n if (typeof fallback === 'function') {\n element = fallback({\n error: state.error,\n componentStack: state.componentStack,\n resetError: this.resetErrorBoundary,\n eventId: state.eventId,\n });\n } else {\n element = fallback;\n }\n\n if (React.isValidElement(element)) {\n return element;\n }\n\n if (fallback) {\n DEBUG_BUILD && logger.warn('fallback did not produce a valid ReactElement');\n }\n\n // Fail gracefully if no fallback provided or is not valid\n return null;\n }\n\n if (typeof children === 'function') {\n return (children as () => React.ReactNode)();\n }\n return children;\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction withErrorBoundary<P extends Record<string, any>>(\n WrappedComponent: React.ComponentType<P>,\n errorBoundaryOptions: ErrorBoundaryProps,\n): React.FC<P> {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const componentDisplayName = WrappedComponent.displayName || WrappedComponent.name || UNKNOWN_COMPONENT;\n\n const Wrapped: React.FC<P> = (props: P) => (\n <ErrorBoundary {...errorBoundaryOptions}>\n <WrappedComponent {...props} />\n </ErrorBoundary>\n );\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n Wrapped.displayName = `errorBoundary(${componentDisplayName})`;\n\n // Copy over static methods from Wrapped component to Profiler HOC\n // See: https://reactjs.org/docs/higher-order-components.html#static-methods-must-be-copied-over\n hoistNonReactStatics(Wrapped, WrappedComponent);\n return Wrapped;\n}\n\nexport { ErrorBoundary, withErrorBoundary };\n"],"names":["React","getClient","showReportDialog","withScope","isError","captureException","DEBUG_BUILD","logger","hoistNonReactStatics"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAA,YA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AA,CAAA;AACA,KAAA;AACA;AACA,IAAA,IAAA,OAAA,QAAA,KAAA,UAAA,EAAA;AACA,MAAA,OAAA,CAAA,QAAA,IAAA,CAAA;AACA,KAAA;AACA,IAAA,OAAA,QAAA,CAAA;AACA,GAAA;AACA,CAAA;AACA;AACA;AACA,SAAA,iBAAA;AACA,EAAA,gBAAA;AACA,EAAA,oBAAA;AACA,EAAA;AACA;AACA,EAAA,MAAA,oBAAA,GAAA,gBAAA,CAAA,WAAA,IAAA,gBAAA,CAAA,IAAA,IAAA,iBAAA,CAAA;AACA;AACA,EAAA,MAAA,OAAA,GAAA,CAAA,KAAA;AACA,IAAAP,gBAAA,CAAA,aAAA,CAAA,aAAA,EAAA,EAAA,GAAA,oBAAA,EAAA,MAAA,EAAA,IAAA,EAAA,QAAA,EAAA,CAAA,QAAA,EAAA,YAAA,EAAA,UAAA,EAAA,GAAA,CAAA,CAAA;AACA,QAAAA,gBAAA,CAAA,aAAA,CAAA,gBAAA,EAAA,EAAA,GAAA,KAAA,EAAA,MAAA,EAAA,IAAA,EAAA,QAAA,EAAA,CAAA,QAAA,EAAA,YAAA,EAAA,UAAA,EAAA,GAAA,CAAA,CAAA,EAAA;AACA,KAAA;AACA,GAAA,CAAA;AACA;AACA;AACA,EAAA,OAAA,CAAA,WAAA,GAAA,CAAA,cAAA,EAAA,oBAAA,CAAA,CAAA,CAAA,CAAA;AACA;AACA;AACA;AACA,EAAAQ,6BAAA,CAAA,OAAA,EAAA,gBAAA,CAAA,CAAA;AACA,EAAA,OAAA,OAAA,CAAA;AACA;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"errorboundary.js","sources":["../../src/errorboundary.tsx"],"sourcesContent":["import type { ReportDialogOptions, Scope } from '@sentry/browser';\nimport { captureException, getClient, showReportDialog, withScope } from '@sentry/browser';\nimport { isError, logger } from '@sentry/utils';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nimport { DEBUG_BUILD } from './debug-build';\n\nexport function isAtLeastReact17(version: string): boolean {\n const major = version.match(/^([^.]+)/);\n return major !== null && parseInt(major[0]) >= 17;\n}\n\nexport const UNKNOWN_COMPONENT = 'unknown';\n\nexport type FallbackRender = (errorData: {\n error: Error;\n componentStack: string;\n eventId: string;\n resetError(): void;\n}) => React.ReactElement;\n\nexport type ErrorBoundaryProps = {\n children?: React.ReactNode | (() => React.ReactNode);\n /** If a Sentry report dialog should be rendered on error */\n showDialog?: boolean | undefined;\n /**\n * Options to be passed into the Sentry report dialog.\n * No-op if {@link showDialog} is false.\n */\n // eslint-disable-next-line deprecation/deprecation\n dialogOptions?: Omit<ReportDialogOptions, 'eventId'> | undefined;\n /**\n * A fallback component that gets rendered when the error boundary encounters an error.\n *\n * Can either provide a React Component, or a function that returns React Component as\n * a valid fallback prop. If a function is provided, the function will be called with\n * the error, the component stack, and an function that resets the error boundary on error.\n *\n */\n fallback?: React.ReactElement | FallbackRender | undefined;\n /** Called when the error boundary encounters an error */\n onError?: ((error: Error, componentStack: string, eventId: string) => void) | undefined;\n /** Called on componentDidMount() */\n onMount?: (() => void) | undefined;\n /** Called if resetError() is called from the fallback render props function */\n onReset?: ((error: Error | null, componentStack: string | null, eventId: string | null) => void) | undefined;\n /** Called on componentWillUnmount() */\n onUnmount?: ((error: Error | null, componentStack: string | null, eventId: string | null) => void) | undefined;\n /** Called before the error is captured by Sentry, allows for you to add tags or context using the scope */\n beforeCapture?: ((scope: Scope, error: Error | null, componentStack: string | null) => void) | undefined;\n};\n\ntype ErrorBoundaryState =\n | {\n componentStack: null;\n error: null;\n eventId: null;\n }\n | {\n componentStack: React.ErrorInfo['componentStack'];\n error: Error;\n eventId: string;\n };\n\nconst INITIAL_STATE = {\n componentStack: null,\n error: null,\n eventId: null,\n};\n\nfunction setCause(error: Error & { cause?: Error }, cause: Error): void {\n const seenErrors = new WeakMap<Error, boolean>();\n\n function recurse(error: Error & { cause?: Error }, cause: Error): void {\n // If we've already seen the error, there is a recursive loop somewhere in the error's\n // cause chain. Let's just bail out then to prevent a stack overflow.\n if (seenErrors.has(error)) {\n return;\n }\n if (error.cause) {\n seenErrors.set(error, true);\n return recurse(error.cause, cause);\n }\n error.cause = cause;\n }\n\n recurse(error, cause);\n}\n\n/**\n * A ErrorBoundary component that logs errors to Sentry. Requires React >= 16.\n * NOTE: If you are a Sentry user, and you are seeing this stack frame, it means the\n * Sentry React SDK ErrorBoundary caught an error invoking your application code. This\n * is expected behavior and NOT indicative of a bug with the Sentry React SDK.\n */\nclass ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> {\n public state: ErrorBoundaryState;\n\n private readonly _openFallbackReportDialog: boolean;\n\n private _lastEventId?: string;\n\n public constructor(props: ErrorBoundaryProps) {\n super(props);\n\n this.state = INITIAL_STATE;\n this._openFallbackReportDialog = true;\n\n const client = getClient();\n if (client && client.on && props.showDialog) {\n this._openFallbackReportDialog = false;\n client.on('afterSendEvent', event => {\n if (!event.type && event.event_id === this._lastEventId) {\n // eslint-disable-next-line deprecation/deprecation\n showReportDialog({ ...props.dialogOptions, eventId: this._lastEventId });\n }\n });\n }\n }\n\n public componentDidCatch(error: Error & { cause?: Error }, { componentStack }: React.ErrorInfo): void {\n const { beforeCapture, onError, showDialog, dialogOptions } = this.props;\n withScope(scope => {\n // If on React version >= 17, create stack trace from componentStack param and links\n // to to the original error using `error.cause` otherwise relies on error param for stacktrace.\n // Linking errors requires the `LinkedErrors` integration be enabled.\n // See: https://reactjs.org/blog/2020/08/10/react-v17-rc.html#native-component-stacks\n //\n // Although `componentDidCatch` is typed to accept an `Error` object, it can also be invoked\n // with non-error objects. This is why we need to check if the error is an error-like object.\n // See: https://github.com/getsentry/sentry-javascript/issues/6167\n if (isAtLeastReact17(React.version) && isError(error)) {\n const errorBoundaryError = new Error(error.message);\n errorBoundaryError.name = `React ErrorBoundary ${error.name}`;\n errorBoundaryError.stack = componentStack;\n\n // Using the `LinkedErrors` integration to link the errors together.\n setCause(error, errorBoundaryError);\n }\n\n if (beforeCapture) {\n beforeCapture(scope, error, componentStack);\n }\n\n const eventId = captureException(error, {\n captureContext: {\n contexts: { react: { componentStack } },\n },\n mechanism: { handled: false },\n });\n\n if (onError) {\n onError(error, componentStack, eventId);\n }\n if (showDialog) {\n this._lastEventId = eventId;\n if (this._openFallbackReportDialog) {\n showReportDialog({ ...dialogOptions, eventId });\n }\n }\n\n // componentDidCatch is used over getDerivedStateFromError\n // so that componentStack is accessible through state.\n this.setState({ error, componentStack, eventId });\n });\n }\n\n public componentDidMount(): void {\n const { onMount } = this.props;\n if (onMount) {\n onMount();\n }\n }\n\n public componentWillUnmount(): void {\n const { error, componentStack, eventId } = this.state;\n const { onUnmount } = this.props;\n if (onUnmount) {\n onUnmount(error, componentStack, eventId);\n }\n }\n\n public resetErrorBoundary: () => void = () => {\n const { onReset } = this.props;\n const { error, componentStack, eventId } = this.state;\n if (onReset) {\n onReset(error, componentStack, eventId);\n }\n this.setState(INITIAL_STATE);\n };\n\n public render(): React.ReactNode {\n const { fallback, children } = this.props;\n const state = this.state;\n\n if (state.error) {\n let element: React.ReactElement | undefined = undefined;\n if (typeof fallback === 'function') {\n element = fallback({\n error: state.error,\n componentStack: state.componentStack,\n resetError: this.resetErrorBoundary,\n eventId: state.eventId,\n });\n } else {\n element = fallback;\n }\n\n if (React.isValidElement(element)) {\n return element;\n }\n\n if (fallback) {\n DEBUG_BUILD && logger.warn('fallback did not produce a valid ReactElement');\n }\n\n // Fail gracefully if no fallback provided or is not valid\n return null;\n }\n\n if (typeof children === 'function') {\n return (children as () => React.ReactNode)();\n }\n return children;\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction withErrorBoundary<P extends Record<string, any>>(\n WrappedComponent: React.ComponentType<P>,\n errorBoundaryOptions: ErrorBoundaryProps,\n): React.FC<P> {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const componentDisplayName = WrappedComponent.displayName || WrappedComponent.name || UNKNOWN_COMPONENT;\n\n const Wrapped: React.FC<P> = (props: P) => (\n <ErrorBoundary {...errorBoundaryOptions}>\n <WrappedComponent {...props} />\n </ErrorBoundary>\n );\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n Wrapped.displayName = `errorBoundary(${componentDisplayName})`;\n\n // Copy over static methods from Wrapped component to Profiler HOC\n // See: https://reactjs.org/docs/higher-order-components.html#static-methods-must-be-copied-over\n hoistNonReactStatics(Wrapped, WrappedComponent);\n return Wrapped;\n}\n\nexport { ErrorBoundary, withErrorBoundary };\n"],"names":["React","getClient","showReportDialog","withScope","isError","captureException","DEBUG_BUILD","logger","hoistNonReactStatics"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAA,YAAA,GAAA,4FAAA,CAAA;AAOA;AACO,SAAS,gBAAgB,CAAC,OAAO,EAAmB;AAC3D,EAAE,MAAM,QAAQ,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;AACzC,EAAE,OAAO,KAAA,KAAU,IAAA,IAAQ,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA,IAAK,EAAE,CAAA;AACnD,CAAA;AACA;AACO,MAAM,iBAAkB,GAAE,UAAS;;AAoD1C,MAAM,gBAAgB;AACtB,EAAE,cAAc,EAAE,IAAI;AACtB,EAAE,KAAK,EAAE,IAAI;AACb,EAAE,OAAO,EAAE,IAAI;AACf,CAAC,CAAA;AACD;AACA,SAAS,QAAQ,CAAC,KAAK,EAA6B,KAAK,EAAe;AACxE,EAAE,MAAM,UAAW,GAAE,IAAI,OAAO,EAAkB,CAAA;AAClD;AACA,EAAE,SAAS,OAAO,CAAC,KAAK,EAA6B,KAAK,EAAe;AACzE;AACA;AACA,IAAI,IAAI,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;AAC/B,MAAM,OAAM;AACZ,KAAI;AACJ,IAAI,IAAI,KAAK,CAAC,KAAK,EAAE;AACrB,MAAM,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;AAC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A,EAAA;AACA,KAAA;AACA,GAAA,CAAA;AACA;AACA;AACA,EAAA,OAAA,CAAA,WAAA,GAAA,CAAA,cAAA,EAAA,oBAAA,CAAA,CAAA,CAAA,CAAA;AACA;AACA;AACA;AACA,EAAAQ,6BAAA,CAAA,OAAA,EAAA,gBAAA,CAAA,CAAA;AACA,EAAA,OAAA,OAAA,CAAA;AACA;;;;;;;"}
|
package/cjs/profiler.js
CHANGED
|
@@ -62,6 +62,7 @@ class Profiler extends React__namespace.Component {
|
|
|
62
62
|
description: `<${name}>`,
|
|
63
63
|
op: constants.REACT_MOUNT_OP,
|
|
64
64
|
origin: 'auto.ui.react.profiler',
|
|
65
|
+
data: { 'ui.component_name': name },
|
|
65
66
|
});
|
|
66
67
|
}
|
|
67
68
|
}
|
|
@@ -69,7 +70,7 @@ class Profiler extends React__namespace.Component {
|
|
|
69
70
|
// If a component mounted, we can finish the mount activity.
|
|
70
71
|
componentDidMount() {
|
|
71
72
|
if (this._mountSpan) {
|
|
72
|
-
this._mountSpan.
|
|
73
|
+
this._mountSpan.end();
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
|
|
@@ -86,6 +87,7 @@ class Profiler extends React__namespace.Component {
|
|
|
86
87
|
this._updateSpan = this._mountSpan.startChild({
|
|
87
88
|
data: {
|
|
88
89
|
changedProps,
|
|
90
|
+
'ui.component_name': this.props.name,
|
|
89
91
|
},
|
|
90
92
|
description: `<${this.props.name}>`,
|
|
91
93
|
op: constants.REACT_UPDATE_OP,
|
|
@@ -100,7 +102,7 @@ class Profiler extends React__namespace.Component {
|
|
|
100
102
|
|
|
101
103
|
componentDidUpdate() {
|
|
102
104
|
if (this._updateSpan) {
|
|
103
|
-
this._updateSpan.
|
|
105
|
+
this._updateSpan.end();
|
|
104
106
|
this._updateSpan = undefined;
|
|
105
107
|
}
|
|
106
108
|
}
|
|
@@ -119,6 +121,7 @@ class Profiler extends React__namespace.Component {
|
|
|
119
121
|
op: constants.REACT_RENDER_OP,
|
|
120
122
|
origin: 'auto.ui.react.profiler',
|
|
121
123
|
startTimestamp: this._mountSpan.endTimestamp,
|
|
124
|
+
data: { 'ui.component_name': name },
|
|
122
125
|
});
|
|
123
126
|
}
|
|
124
127
|
}
|
|
@@ -145,8 +148,8 @@ function withProfiler(
|
|
|
145
148
|
(options && options.name) || WrappedComponent.displayName || WrappedComponent.name || UNKNOWN_COMPONENT;
|
|
146
149
|
|
|
147
150
|
const Wrapped = (props) => (
|
|
148
|
-
React__namespace.createElement(Profiler, { ...options, name: componentDisplayName, updateProps: props, __self: this, __source: {fileName: _jsxFileName, lineNumber:
|
|
149
|
-
, React__namespace.createElement(WrappedComponent, { ...props, __self: this, __source: {fileName: _jsxFileName, lineNumber:
|
|
151
|
+
React__namespace.createElement(Profiler, { ...options, name: componentDisplayName, updateProps: props, __self: this, __source: {fileName: _jsxFileName, lineNumber: 152}}
|
|
152
|
+
, React__namespace.createElement(WrappedComponent, { ...props, __self: this, __source: {fileName: _jsxFileName, lineNumber: 153}} )
|
|
150
153
|
)
|
|
151
154
|
);
|
|
152
155
|
|
|
@@ -183,6 +186,7 @@ function useProfiler(
|
|
|
183
186
|
description: `<${name}>`,
|
|
184
187
|
op: constants.REACT_MOUNT_OP,
|
|
185
188
|
origin: 'auto.ui.react.profiler',
|
|
189
|
+
data: { 'ui.component_name': name },
|
|
186
190
|
});
|
|
187
191
|
}
|
|
188
192
|
|
|
@@ -191,7 +195,7 @@ function useProfiler(
|
|
|
191
195
|
|
|
192
196
|
React__namespace.useEffect(() => {
|
|
193
197
|
if (mountSpan) {
|
|
194
|
-
mountSpan.
|
|
198
|
+
mountSpan.end();
|
|
195
199
|
}
|
|
196
200
|
|
|
197
201
|
return () => {
|
|
@@ -202,6 +206,7 @@ function useProfiler(
|
|
|
202
206
|
op: constants.REACT_RENDER_OP,
|
|
203
207
|
origin: 'auto.ui.react.profiler',
|
|
204
208
|
startTimestamp: mountSpan.endTimestamp,
|
|
209
|
+
data: { 'ui.component_name': name },
|
|
205
210
|
});
|
|
206
211
|
}
|
|
207
212
|
};
|
package/cjs/profiler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profiler.js","sources":["../../src/profiler.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { Hub } from '@sentry/browser';\nimport { getCurrentHub } from '@sentry/browser';\nimport type { Span, Transaction } from '@sentry/types';\nimport { timestampInSeconds } from '@sentry/utils';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nimport { REACT_MOUNT_OP, REACT_RENDER_OP, REACT_UPDATE_OP } from './constants';\n\nexport const UNKNOWN_COMPONENT = 'unknown';\n\nexport type ProfilerProps = {\n // The name of the component being profiled.\n name: string;\n // If the Profiler is disabled. False by default. This is useful if you want to disable profilers\n // in certain environments.\n disabled?: boolean;\n // If time component is on page should be displayed as spans. True by default.\n includeRender?: boolean;\n // If component updates should be displayed as spans. True by default.\n includeUpdates?: boolean;\n // Component that is being profiled.\n children?: React.ReactNode;\n // props given to component being profiled.\n updateProps: { [key: string]: unknown };\n};\n\n/**\n * The Profiler component leverages Sentry's Tracing integration to generate\n * spans based on component lifecycles.\n */\nclass Profiler extends React.Component<ProfilerProps> {\n /**\n * The span of the mount activity\n * Made protected for the React Native SDK to access\n */\n protected _mountSpan: Span | undefined;\n /**\n * The span that represents the duration of time between shouldComponentUpdate and componentDidUpdate\n */\n protected _updateSpan: Span | undefined;\n\n // eslint-disable-next-line @typescript-eslint/member-ordering\n public static defaultProps: Partial<ProfilerProps> = {\n disabled: false,\n includeRender: true,\n includeUpdates: true,\n };\n\n public constructor(props: ProfilerProps) {\n super(props);\n const { name, disabled = false } = this.props;\n\n if (disabled) {\n return;\n }\n\n const activeTransaction = getActiveTransaction();\n if (activeTransaction) {\n this._mountSpan = activeTransaction.startChild({\n description: `<${name}>`,\n op: REACT_MOUNT_OP,\n origin: 'auto.ui.react.profiler',\n });\n }\n }\n\n // If a component mounted, we can finish the mount activity.\n public componentDidMount(): void {\n if (this._mountSpan) {\n this._mountSpan.finish();\n }\n }\n\n public shouldComponentUpdate({ updateProps, includeUpdates = true }: ProfilerProps): boolean {\n // Only generate an update span if includeUpdates is true, if there is a valid mountSpan,\n // and if the updateProps have changed. It is ok to not do a deep equality check here as it is expensive.\n // We are just trying to give baseline clues for further investigation.\n if (includeUpdates && this._mountSpan && updateProps !== this.props.updateProps) {\n // See what props haved changed between the previous props, and the current props. This is\n // set as data on the span. We just store the prop keys as the values could be potenially very large.\n const changedProps = Object.keys(updateProps).filter(k => updateProps[k] !== this.props.updateProps[k]);\n if (changedProps.length > 0) {\n const now = timestampInSeconds();\n this._updateSpan = this._mountSpan.startChild({\n data: {\n changedProps,\n },\n description: `<${this.props.name}>`,\n op: REACT_UPDATE_OP,\n origin: 'auto.ui.react.profiler',\n startTimestamp: now,\n });\n }\n }\n\n return true;\n }\n\n public componentDidUpdate(): void {\n if (this._updateSpan) {\n this._updateSpan.finish();\n this._updateSpan = undefined;\n }\n }\n\n // If a component is unmounted, we can say it is no longer on the screen.\n // This means we can finish the span representing the component render.\n public componentWillUnmount(): void {\n const { name, includeRender = true } = this.props;\n\n if (this._mountSpan && includeRender) {\n // If we were able to obtain the spanId of the mount activity, we should set the\n // next activity as a child to the component mount activity.\n this._mountSpan.startChild({\n description: `<${name}>`,\n endTimestamp: timestampInSeconds(),\n op: REACT_RENDER_OP,\n origin: 'auto.ui.react.profiler',\n startTimestamp: this._mountSpan.endTimestamp,\n });\n }\n }\n\n public render(): React.ReactNode {\n return this.props.children;\n }\n}\n\n/**\n * withProfiler is a higher order component that wraps a\n * component in a {@link Profiler} component. It is recommended that\n * the higher order component be used over the regular {@link Profiler} component.\n *\n * @param WrappedComponent component that is wrapped by Profiler\n * @param options the {@link ProfilerProps} you can pass into the Profiler\n */\nfunction withProfiler<P extends Record<string, any>>(\n WrappedComponent: React.ComponentType<P>,\n // We do not want to have `updateProps` given in options, it is instead filled through the HOC.\n options?: Pick<Partial<ProfilerProps>, Exclude<keyof ProfilerProps, 'updateProps' | 'children'>>,\n): React.FC<P> {\n const componentDisplayName =\n (options && options.name) || WrappedComponent.displayName || WrappedComponent.name || UNKNOWN_COMPONENT;\n\n const Wrapped: React.FC<P> = (props: P) => (\n <Profiler {...options} name={componentDisplayName} updateProps={props}>\n <WrappedComponent {...props} />\n </Profiler>\n );\n\n Wrapped.displayName = `profiler(${componentDisplayName})`;\n\n // Copy over static methods from Wrapped component to Profiler HOC\n // See: https://reactjs.org/docs/higher-order-components.html#static-methods-must-be-copied-over\n hoistNonReactStatics(Wrapped, WrappedComponent);\n return Wrapped;\n}\n\n/**\n *\n * `useProfiler` is a React hook that profiles a React component.\n *\n * Requires React 16.8 or above.\n * @param name displayName of component being profiled\n */\nfunction useProfiler(\n name: string,\n options: { disabled?: boolean; hasRenderSpan?: boolean } = {\n disabled: false,\n hasRenderSpan: true,\n },\n): void {\n const [mountSpan] = React.useState(() => {\n if (options && options.disabled) {\n return undefined;\n }\n\n const activeTransaction = getActiveTransaction();\n if (activeTransaction) {\n return activeTransaction.startChild({\n description: `<${name}>`,\n op: REACT_MOUNT_OP,\n origin: 'auto.ui.react.profiler',\n });\n }\n\n return undefined;\n });\n\n React.useEffect(() => {\n if (mountSpan) {\n mountSpan.finish();\n }\n\n return (): void => {\n if (mountSpan && options.hasRenderSpan) {\n mountSpan.startChild({\n description: `<${name}>`,\n endTimestamp: timestampInSeconds(),\n op: REACT_RENDER_OP,\n origin: 'auto.ui.react.profiler',\n startTimestamp: mountSpan.endTimestamp,\n });\n }\n };\n // We only want this to run once.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n}\n\nexport { withProfiler, Profiler, useProfiler };\n\n/** Grabs active transaction off scope */\nexport function getActiveTransaction<T extends Transaction>(hub: Hub = getCurrentHub()): T | undefined {\n if (hub) {\n const scope = hub.getScope();\n return scope.getTransaction() as T | undefined;\n }\n\n return undefined;\n}\n"],"names":["React","REACT_MOUNT_OP","timestampInSeconds","REACT_UPDATE_OP","REACT_RENDER_OP","hoistNonReactStatics","getCurrentHub"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAA,YAAA,GAAA,uFAAA,CAAA;AAUA;AACA,MAAA,iBAAA,GAAA,UAAA;;AAkBA;AACA;AACA;AACA;AACA,MAAA,QAAA,SAAAA,gBAAA,CAAA,SAAA,CAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAGA;AACA,GAAA,OAAA,YAAA,GAAA,CAAA,IAAA,CAAA,YAAA,GAAA;AACA,IAAA,QAAA,EAAA,KAAA;AACA,IAAA,aAAA,EAAA,IAAA;AACA,IAAA,cAAA,EAAA,IAAA;AACA,IAAA,CAAA;AACA;AACA,GAAA,WAAA,CAAA,KAAA,EAAA;AACA,IAAA,KAAA,CAAA,KAAA,CAAA,CAAA;AACA,IAAA,MAAA,EAAA,IAAA,EAAA,QAAA,GAAA,KAAA,EAAA,GAAA,IAAA,CAAA,KAAA,CAAA;AACA;AACA,IAAA,IAAA,QAAA,EAAA;AACA,MAAA,OAAA;AACA,KAAA;AACA;AACA,IAAA,MAAA,iBAAA,GAAA,oBAAA,EAAA,CAAA;AACA,IAAA,IAAA,iBAAA,EAAA;AACA,MAAA,IAAA,CAAA,UAAA,GAAA,iBAAA,CAAA,UAAA,CAAA;AACA,QAAA,WAAA,EAAA,CAAA,CAAA,EAAA,IAAA,CAAA,CAAA,CAAA;AACA,QAAA,EAAA,EAAAC,wBAAA;AACA,QAAA,MAAA,EAAA,wBAAA;AACA,OAAA,CAAA,CAAA;AACA,KAAA;AACA,GAAA;AACA;AACA;AACA,GAAA,iBAAA,GAAA;AACA,IAAA,IAAA,IAAA,CAAA,UAAA,EAAA;AACA,MAAA,IAAA,CAAA,UAAA,CAAA,MAAA,EAAA,CAAA;AACA,KAAA;AACA,GAAA;AACA;AACA,GAAA,qBAAA,CAAA,EAAA,WAAA,EAAA,cAAA,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AAA,CAAA,YAAA;AACA,SAAA,CAAA,CAAA;AACA,OAAA;AACA,KAAA,CAAA;AACA;AACA;AACA,GAAA,EAAA,EAAA,CAAA,CAAA;AACA,CAAA;AAGA;AACA;AACA,SAAA,oBAAA,CAAA,GAAA,GAAAE,qBAAA,EAAA,EAAA;AACA,EAAA,IAAA,GAAA,EAAA;AACA,IAAA,MAAA,KAAA,GAAA,GAAA,CAAA,QAAA,EAAA,CAAA;AACA,IAAA,OAAA,KAAA,CAAA,cAAA,EAAA,EAAA;AACA,GAAA;AACA;AACA,EAAA,OAAA,SAAA,CAAA;AACA;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"profiler.js","sources":["../../src/profiler.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { Hub } from '@sentry/browser';\nimport { getCurrentHub } from '@sentry/browser';\nimport type { Span, Transaction } from '@sentry/types';\nimport { timestampInSeconds } from '@sentry/utils';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nimport { REACT_MOUNT_OP, REACT_RENDER_OP, REACT_UPDATE_OP } from './constants';\n\nexport const UNKNOWN_COMPONENT = 'unknown';\n\nexport type ProfilerProps = {\n // The name of the component being profiled.\n name: string;\n // If the Profiler is disabled. False by default. This is useful if you want to disable profilers\n // in certain environments.\n disabled?: boolean;\n // If time component is on page should be displayed as spans. True by default.\n includeRender?: boolean;\n // If component updates should be displayed as spans. True by default.\n includeUpdates?: boolean;\n // Component that is being profiled.\n children?: React.ReactNode;\n // props given to component being profiled.\n updateProps: { [key: string]: unknown };\n};\n\n/**\n * The Profiler component leverages Sentry's Tracing integration to generate\n * spans based on component lifecycles.\n */\nclass Profiler extends React.Component<ProfilerProps> {\n /**\n * The span of the mount activity\n * Made protected for the React Native SDK to access\n */\n protected _mountSpan: Span | undefined;\n /**\n * The span that represents the duration of time between shouldComponentUpdate and componentDidUpdate\n */\n protected _updateSpan: Span | undefined;\n\n // eslint-disable-next-line @typescript-eslint/member-ordering\n public static defaultProps: Partial<ProfilerProps> = {\n disabled: false,\n includeRender: true,\n includeUpdates: true,\n };\n\n public constructor(props: ProfilerProps) {\n super(props);\n const { name, disabled = false } = this.props;\n\n if (disabled) {\n return;\n }\n\n const activeTransaction = getActiveTransaction();\n if (activeTransaction) {\n this._mountSpan = activeTransaction.startChild({\n description: `<${name}>`,\n op: REACT_MOUNT_OP,\n origin: 'auto.ui.react.profiler',\n data: { 'ui.component_name': name },\n });\n }\n }\n\n // If a component mounted, we can finish the mount activity.\n public componentDidMount(): void {\n if (this._mountSpan) {\n this._mountSpan.end();\n }\n }\n\n public shouldComponentUpdate({ updateProps, includeUpdates = true }: ProfilerProps): boolean {\n // Only generate an update span if includeUpdates is true, if there is a valid mountSpan,\n // and if the updateProps have changed. It is ok to not do a deep equality check here as it is expensive.\n // We are just trying to give baseline clues for further investigation.\n if (includeUpdates && this._mountSpan && updateProps !== this.props.updateProps) {\n // See what props haved changed between the previous props, and the current props. This is\n // set as data on the span. We just store the prop keys as the values could be potenially very large.\n const changedProps = Object.keys(updateProps).filter(k => updateProps[k] !== this.props.updateProps[k]);\n if (changedProps.length > 0) {\n const now = timestampInSeconds();\n this._updateSpan = this._mountSpan.startChild({\n data: {\n changedProps,\n 'ui.component_name': this.props.name,\n },\n description: `<${this.props.name}>`,\n op: REACT_UPDATE_OP,\n origin: 'auto.ui.react.profiler',\n startTimestamp: now,\n });\n }\n }\n\n return true;\n }\n\n public componentDidUpdate(): void {\n if (this._updateSpan) {\n this._updateSpan.end();\n this._updateSpan = undefined;\n }\n }\n\n // If a component is unmounted, we can say it is no longer on the screen.\n // This means we can finish the span representing the component render.\n public componentWillUnmount(): void {\n const { name, includeRender = true } = this.props;\n\n if (this._mountSpan && includeRender) {\n // If we were able to obtain the spanId of the mount activity, we should set the\n // next activity as a child to the component mount activity.\n this._mountSpan.startChild({\n description: `<${name}>`,\n endTimestamp: timestampInSeconds(),\n op: REACT_RENDER_OP,\n origin: 'auto.ui.react.profiler',\n startTimestamp: this._mountSpan.endTimestamp,\n data: { 'ui.component_name': name },\n });\n }\n }\n\n public render(): React.ReactNode {\n return this.props.children;\n }\n}\n\n/**\n * withProfiler is a higher order component that wraps a\n * component in a {@link Profiler} component. It is recommended that\n * the higher order component be used over the regular {@link Profiler} component.\n *\n * @param WrappedComponent component that is wrapped by Profiler\n * @param options the {@link ProfilerProps} you can pass into the Profiler\n */\nfunction withProfiler<P extends Record<string, any>>(\n WrappedComponent: React.ComponentType<P>,\n // We do not want to have `updateProps` given in options, it is instead filled through the HOC.\n options?: Pick<Partial<ProfilerProps>, Exclude<keyof ProfilerProps, 'updateProps' | 'children'>>,\n): React.FC<P> {\n const componentDisplayName =\n (options && options.name) || WrappedComponent.displayName || WrappedComponent.name || UNKNOWN_COMPONENT;\n\n const Wrapped: React.FC<P> = (props: P) => (\n <Profiler {...options} name={componentDisplayName} updateProps={props}>\n <WrappedComponent {...props} />\n </Profiler>\n );\n\n Wrapped.displayName = `profiler(${componentDisplayName})`;\n\n // Copy over static methods from Wrapped component to Profiler HOC\n // See: https://reactjs.org/docs/higher-order-components.html#static-methods-must-be-copied-over\n hoistNonReactStatics(Wrapped, WrappedComponent);\n return Wrapped;\n}\n\n/**\n *\n * `useProfiler` is a React hook that profiles a React component.\n *\n * Requires React 16.8 or above.\n * @param name displayName of component being profiled\n */\nfunction useProfiler(\n name: string,\n options: { disabled?: boolean; hasRenderSpan?: boolean } = {\n disabled: false,\n hasRenderSpan: true,\n },\n): void {\n const [mountSpan] = React.useState(() => {\n if (options && options.disabled) {\n return undefined;\n }\n\n const activeTransaction = getActiveTransaction();\n if (activeTransaction) {\n return activeTransaction.startChild({\n description: `<${name}>`,\n op: REACT_MOUNT_OP,\n origin: 'auto.ui.react.profiler',\n data: { 'ui.component_name': name },\n });\n }\n\n return undefined;\n });\n\n React.useEffect(() => {\n if (mountSpan) {\n mountSpan.end();\n }\n\n return (): void => {\n if (mountSpan && options.hasRenderSpan) {\n mountSpan.startChild({\n description: `<${name}>`,\n endTimestamp: timestampInSeconds(),\n op: REACT_RENDER_OP,\n origin: 'auto.ui.react.profiler',\n startTimestamp: mountSpan.endTimestamp,\n data: { 'ui.component_name': name },\n });\n }\n };\n // We only want this to run once.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n}\n\nexport { withProfiler, Profiler, useProfiler };\n\n/** Grabs active transaction off scope */\nexport function getActiveTransaction<T extends Transaction>(hub: Hub = getCurrentHub()): T | undefined {\n if (hub) {\n const scope = hub.getScope();\n return scope.getTransaction() as T | undefined;\n }\n\n return undefined;\n}\n"],"names":["React","REACT_MOUNT_OP","timestampInSeconds","REACT_UPDATE_OP","REACT_RENDER_OP","hoistNonReactStatics","getCurrentHub"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAA,YAAA,GAAA,uFAAA,CAAA;AAUA;AACO,MAAM,iBAAkB,GAAE,UAAS;;AAkB1C;AACA;AACA;AACA;AACA,MAAM,QAAS,SAAQA,gBAAK,CAAC,SAAS,CAAgB;AACtD;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAGA;AACA,GAAS,OAAA,YAAA,GAAA,CAAA,IAAA,CAAO,YAAY,GAA2B;AACvD,IAAI,QAAQ,EAAE,KAAK;AACnB,IAAI,aAAa,EAAE,IAAI;AACvB,IAAI,cAAc,EAAE,IAAI;AACxB,IAAG,CAAA;AACH;AACA,GAAS,WAAW,CAAC,KAAK,EAAiB;AAC3C,IAAI,KAAK,CAAC,KAAK,CAAC,CAAA;AAChB,IAAI,MAAM,EAAE,IAAI,EAAE,QAAA,GAAW,KAAA,EAAQ,GAAE,IAAI,CAAC,KAAK,CAAA;AACjD;AACA,IAAI,IAAI,QAAQ,EAAE;AAClB,MAAM,OAAM;AACZ,KAAI;AACJ;AACA,IAAI,MAAM,iBAAA,GAAoB,oBAAoB,EAAE,CAAA;AACpD,IAAI,IAAI,iBAAiB,EAAE;AAC3B,MAA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rumentation(
|
|
|
108
108
|
history.listen((location, action) => {
|
|
109
109
|
if (action && (action === 'PUSH' || action === 'POP')) {
|
|
110
110
|
if (activeTransaction) {
|
|
111
|
-
activeTransaction.
|
|
111
|
+
activeTransaction.end();
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
const [name, source] = normalizeTransactionName(location.pathname);
|
|
@@ -168,13 +168,14 @@ function withSentryRouting(Route) {
|
|
|
168
168
|
|
|
169
169
|
const WrappedRoute = (props) => {
|
|
170
170
|
if (activeTransaction && props && props.computedMatch && props.computedMatch.isExact) {
|
|
171
|
-
activeTransaction.
|
|
171
|
+
activeTransaction.updateName(props.computedMatch.path);
|
|
172
|
+
activeTransaction.setMetadata({ source: 'route' });
|
|
172
173
|
}
|
|
173
174
|
|
|
174
175
|
// @ts-expect-error Setting more specific React Component typing for `R` generic above
|
|
175
176
|
// will break advanced type inference done by react router params:
|
|
176
177
|
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164
|
|
177
|
-
return React__namespace.createElement(Route, { ...props, __self: this, __source: {fileName: _jsxFileName, lineNumber:
|
|
178
|
+
return React__namespace.createElement(Route, { ...props, __self: this, __source: {fileName: _jsxFileName, lineNumber: 175}} );
|
|
178
179
|
};
|
|
179
180
|
|
|
180
181
|
WrappedRoute.displayName = `sentryRoute(${componentDisplayName})`;
|
package/cjs/reactrouter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactrouter.js","sources":["../../src/reactrouter.tsx"],"sourcesContent":["import { WINDOW } from '@sentry/browser';\nimport type { Transaction, TransactionSource } from '@sentry/types';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nimport type { Action, Location, ReactRouterInstrumentation } from './types';\n\n// We need to disable eslint no-explict-any because any is required for the\n// react-router typings.\ntype Match = { path: string; url: string; params: Record<string, any>; isExact: boolean }; // eslint-disable-line @typescript-eslint/no-explicit-any\n\nexport type RouterHistory = {\n location?: Location;\n listen?(cb: (location: Location, action: Action) => void): void;\n} & Record<string, any>; // eslint-disable-line @typescript-eslint/no-explicit-any\n\nexport type RouteConfig = {\n [propName: string]: unknown;\n path?: string | string[];\n exact?: boolean;\n component?: JSX.Element;\n routes?: RouteConfig[];\n};\n\ntype MatchPath = (pathname: string, props: string | string[] | any, parent?: Match | null) => Match | null; // eslint-disable-line @typescript-eslint/no-explicit-any\n\nlet activeTransaction: Transaction | undefined;\n\nexport function reactRouterV4Instrumentation(\n history: RouterHistory,\n routes?: RouteConfig[],\n matchPath?: MatchPath,\n): ReactRouterInstrumentation {\n return createReactRouterInstrumentation(history, 'react-router-v4', routes, matchPath);\n}\n\nexport function reactRouterV5Instrumentation(\n history: RouterHistory,\n routes?: RouteConfig[],\n matchPath?: MatchPath,\n): ReactRouterInstrumentation {\n return createReactRouterInstrumentation(history, 'react-router-v5', routes, matchPath);\n}\n\nfunction createReactRouterInstrumentation(\n history: RouterHistory,\n name: string,\n allRoutes: RouteConfig[] = [],\n matchPath?: MatchPath,\n): ReactRouterInstrumentation {\n function getInitPathName(): string | undefined {\n if (history && history.location) {\n return history.location.pathname;\n }\n\n if (WINDOW && WINDOW.location) {\n return WINDOW.location.pathname;\n }\n\n return undefined;\n }\n\n /**\n * Normalizes a transaction name. Returns the new name as well as the\n * source of the transaction.\n *\n * @param pathname The initial pathname we normalize\n */\n function normalizeTransactionName(pathname: string): [string, TransactionSource] {\n if (allRoutes.length === 0 || !matchPath) {\n return [pathname, 'url'];\n }\n\n const branches = matchRoutes(allRoutes, pathname, matchPath);\n // eslint-disable-next-line @typescript-eslint/prefer-for-of\n for (let x = 0; x < branches.length; x++) {\n if (branches[x].match.isExact) {\n return [branches[x].match.path, 'route'];\n }\n }\n\n return [pathname, 'url'];\n }\n\n const tags = {\n 'routing.instrumentation': name,\n };\n\n return (customStartTransaction, startTransactionOnPageLoad = true, startTransactionOnLocationChange = true): void => {\n const initPathName = getInitPathName();\n if (startTransactionOnPageLoad && initPathName) {\n const [name, source] = normalizeTransactionName(initPathName);\n activeTransaction = customStartTransaction({\n name,\n op: 'pageload',\n origin: 'auto.pageload.react.reactrouter',\n tags,\n metadata: {\n source,\n },\n });\n }\n\n if (startTransactionOnLocationChange && history.listen) {\n history.listen((location, action) => {\n if (action && (action === 'PUSH' || action === 'POP')) {\n if (activeTransaction) {\n activeTransaction.finish();\n }\n\n const [name, source] = normalizeTransactionName(location.pathname);\n activeTransaction = customStartTransaction({\n name,\n op: 'navigation',\n origin: 'auto.navigation.react.reactrouter',\n tags,\n metadata: {\n source,\n },\n });\n }\n });\n }\n };\n}\n\n/**\n * Matches a set of routes to a pathname\n * Based on implementation from\n */\nfunction matchRoutes(\n routes: RouteConfig[],\n pathname: string,\n matchPath: MatchPath,\n branch: Array<{ route: RouteConfig; match: Match }> = [],\n): Array<{ route: RouteConfig; match: Match }> {\n routes.some(route => {\n const match = route.path\n ? matchPath(pathname, route)\n : branch.length\n ? branch[branch.length - 1].match // use parent match\n : computeRootMatch(pathname); // use default \"root\" match\n\n if (match) {\n branch.push({ route, match });\n\n if (route.routes) {\n matchRoutes(route.routes, pathname, matchPath, branch);\n }\n }\n\n return !!match;\n });\n\n return branch;\n}\n\nfunction computeRootMatch(pathname: string): Match {\n return { path: '/', url: '/', params: {}, isExact: pathname === '/' };\n}\n\n/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */\nexport function withSentryRouting<P extends Record<string, any>, R extends React.ComponentType<P>>(Route: R): R {\n const componentDisplayName = (Route as any).displayName || (Route as any).name;\n\n const WrappedRoute: React.FC<P> = (props: P) => {\n if (activeTransaction && props && props.computedMatch && props.computedMatch.isExact) {\n activeTransaction.setName(props.computedMatch.path, 'route');\n }\n\n // @ts-expect-error Setting more specific React Component typing for `R` generic above\n // will break advanced type inference done by react router params:\n // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164\n return <Route {...props} />;\n };\n\n WrappedRoute.displayName = `sentryRoute(${componentDisplayName})`;\n hoistNonReactStatics(WrappedRoute, Route);\n // @ts-expect-error Setting more specific React Component typing for `R` generic above\n // will break advanced type inference done by react router params:\n // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164\n return WrappedRoute;\n}\n/* eslint-enable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */\n"],"names":["WINDOW","React","hoistNonReactStatics"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAA,YAAA,GAAA,0FAAA;AAOA;AACA;;AAgBA;AACA;AACA,IAAA,iBAAA,CAAA;AACA;AACA,SAAA,4BAAA;AACA,EAAA,OAAA;AACA,EAAA,MAAA;AACA,EAAA,SAAA;AACA,EAAA;AACA,EAAA,OAAA,gCAAA,CAAA,OAAA,EAAA,iBAAA,EAAA,MAAA,EAAA,SAAA,CAAA,CAAA;AACA,CAAA;AACA;AACA,SAAA,4BAAA;AACA,EAAA,OAAA;AACA,EAAA,MAAA;AACA,EAAA,SAAA;AACA,EAAA;AACA,EAAA,OAAA,gCAAA,CAAA,OAAA,EAAA,iBAAA,EAAA,MAAA,EAAA,SAAA,CAAA,CAAA;AACA,CAAA;AACA;AACA,SAAA,gCAAA;AACA,EAAA,OAAA;AACA,EAAA,IAAA;AACA,EAAA,SAAA,GAAA,EAAA;AACA,EAAA,SAAA;AACA,EAAA;AACA,EAAA,SAAA,eAAA,GAAA;AACA,IAAA,IAAA,OAAA,IAAA,OAAA,CAAA,QAAA,EAAA;AACA,MAAA,OAAA,OAAA,CAAA,QAAA,CAAA,QAAA,CAAA;AACA,KAAA;AACA;AACA,IAAA,IAAAA,cAAA,IAAAA,cAAA,CAAA,QAAA,EAAA;AACA,MAAA,OAAAA,cAAA,CAAA,QAAA,CAAA,QAAA,CAAA;AACA,KA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EAAA,OAAA,YAAA,CAAA;AACA,CAAA;AACA;;;;;;"}
|
|
1
|
+
{"version":3,"file":"reactrouter.js","sources":["../../src/reactrouter.tsx"],"sourcesContent":["import { WINDOW } from '@sentry/browser';\nimport type { Transaction, TransactionSource } from '@sentry/types';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nimport type { Action, Location, ReactRouterInstrumentation } from './types';\n\n// We need to disable eslint no-explict-any because any is required for the\n// react-router typings.\ntype Match = { path: string; url: string; params: Record<string, any>; isExact: boolean }; // eslint-disable-line @typescript-eslint/no-explicit-any\n\nexport type RouterHistory = {\n location?: Location;\n listen?(cb: (location: Location, action: Action) => void): void;\n} & Record<string, any>; // eslint-disable-line @typescript-eslint/no-explicit-any\n\nexport type RouteConfig = {\n [propName: string]: unknown;\n path?: string | string[];\n exact?: boolean;\n component?: JSX.Element;\n routes?: RouteConfig[];\n};\n\ntype MatchPath = (pathname: string, props: string | string[] | any, parent?: Match | null) => Match | null; // eslint-disable-line @typescript-eslint/no-explicit-any\n\nlet activeTransaction: Transaction | undefined;\n\nexport function reactRouterV4Instrumentation(\n history: RouterHistory,\n routes?: RouteConfig[],\n matchPath?: MatchPath,\n): ReactRouterInstrumentation {\n return createReactRouterInstrumentation(history, 'react-router-v4', routes, matchPath);\n}\n\nexport function reactRouterV5Instrumentation(\n history: RouterHistory,\n routes?: RouteConfig[],\n matchPath?: MatchPath,\n): ReactRouterInstrumentation {\n return createReactRouterInstrumentation(history, 'react-router-v5', routes, matchPath);\n}\n\nfunction createReactRouterInstrumentation(\n history: RouterHistory,\n name: string,\n allRoutes: RouteConfig[] = [],\n matchPath?: MatchPath,\n): ReactRouterInstrumentation {\n function getInitPathName(): string | undefined {\n if (history && history.location) {\n return history.location.pathname;\n }\n\n if (WINDOW && WINDOW.location) {\n return WINDOW.location.pathname;\n }\n\n return undefined;\n }\n\n /**\n * Normalizes a transaction name. Returns the new name as well as the\n * source of the transaction.\n *\n * @param pathname The initial pathname we normalize\n */\n function normalizeTransactionName(pathname: string): [string, TransactionSource] {\n if (allRoutes.length === 0 || !matchPath) {\n return [pathname, 'url'];\n }\n\n const branches = matchRoutes(allRoutes, pathname, matchPath);\n // eslint-disable-next-line @typescript-eslint/prefer-for-of\n for (let x = 0; x < branches.length; x++) {\n if (branches[x].match.isExact) {\n return [branches[x].match.path, 'route'];\n }\n }\n\n return [pathname, 'url'];\n }\n\n const tags = {\n 'routing.instrumentation': name,\n };\n\n return (customStartTransaction, startTransactionOnPageLoad = true, startTransactionOnLocationChange = true): void => {\n const initPathName = getInitPathName();\n if (startTransactionOnPageLoad && initPathName) {\n const [name, source] = normalizeTransactionName(initPathName);\n activeTransaction = customStartTransaction({\n name,\n op: 'pageload',\n origin: 'auto.pageload.react.reactrouter',\n tags,\n metadata: {\n source,\n },\n });\n }\n\n if (startTransactionOnLocationChange && history.listen) {\n history.listen((location, action) => {\n if (action && (action === 'PUSH' || action === 'POP')) {\n if (activeTransaction) {\n activeTransaction.end();\n }\n\n const [name, source] = normalizeTransactionName(location.pathname);\n activeTransaction = customStartTransaction({\n name,\n op: 'navigation',\n origin: 'auto.navigation.react.reactrouter',\n tags,\n metadata: {\n source,\n },\n });\n }\n });\n }\n };\n}\n\n/**\n * Matches a set of routes to a pathname\n * Based on implementation from\n */\nfunction matchRoutes(\n routes: RouteConfig[],\n pathname: string,\n matchPath: MatchPath,\n branch: Array<{ route: RouteConfig; match: Match }> = [],\n): Array<{ route: RouteConfig; match: Match }> {\n routes.some(route => {\n const match = route.path\n ? matchPath(pathname, route)\n : branch.length\n ? branch[branch.length - 1].match // use parent match\n : computeRootMatch(pathname); // use default \"root\" match\n\n if (match) {\n branch.push({ route, match });\n\n if (route.routes) {\n matchRoutes(route.routes, pathname, matchPath, branch);\n }\n }\n\n return !!match;\n });\n\n return branch;\n}\n\nfunction computeRootMatch(pathname: string): Match {\n return { path: '/', url: '/', params: {}, isExact: pathname === '/' };\n}\n\n/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */\nexport function withSentryRouting<P extends Record<string, any>, R extends React.ComponentType<P>>(Route: R): R {\n const componentDisplayName = (Route as any).displayName || (Route as any).name;\n\n const WrappedRoute: React.FC<P> = (props: P) => {\n if (activeTransaction && props && props.computedMatch && props.computedMatch.isExact) {\n activeTransaction.updateName(props.computedMatch.path);\n activeTransaction.setMetadata({ source: 'route' });\n }\n\n // @ts-expect-error Setting more specific React Component typing for `R` generic above\n // will break advanced type inference done by react router params:\n // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164\n return <Route {...props} />;\n };\n\n WrappedRoute.displayName = `sentryRoute(${componentDisplayName})`;\n hoistNonReactStatics(WrappedRoute, Route);\n // @ts-expect-error Setting more specific React Component typing for `R` generic above\n // will break advanced type inference done by react router params:\n // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164\n return WrappedRoute;\n}\n/* eslint-enable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */\n"],"names":["WINDOW","React","hoistNonReactStatics"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAA,YAAA,GAAA,0FAAA;AAOA;AACA;;AAgBA;AACA;AACA,IAAI,iBAAiB,CAAA;AACrB;AACO,SAAS,4BAA4B;AAC5C,EAAE,OAAO;AACT,EAAE,MAAM;AACR,EAAE,SAAS;AACX,EAA8B;AAC9B,EAAE,OAAO,gCAAgC,CAAC,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;AACxF,CAAA;AACA;AACO,SAAS,4BAA4B;AAC5C,EAAE,OAAO;AACT,EAAE,MAAM;AACR,EAAE,SAAS;AACX,EAA8B;AAC9B,EAAE,OAAO,gCAAgC,CAAC,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,SAAS,CAAC,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AAS,KAAK,CAAC,aAAA,IAAiB,KAAK,CAAC,aAAa,CAAC,OAAO,EAAE;AAC1F,MAAM,iBAAiB,CAAC,UAAU,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,CAAA;AAC5D,MAAM,iBAAiB,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,OAAQ,EAAC,CAAC,CAAA;AACxD,KAAI;AACJ;AACA;AACA;AACA;AACA,IAAI,OAAOC,gBAAC,CAAA,aAAA,CAAA,KAAA,EAAA,EAAM,GAAI,KAAK,sEAAI,CAAA;AAC/B,GAAG,CAAA;AACH;AACA,EAAE,YAAY,CAAC,WAAA,GAAc,CAAC,YAAY,EAAE,oBAAoB,CAAC,CAAC,CAAC,CAAA;AACnE,EAAEC,6BAAoB,CAAC,YAAY,EAAE,KAAK,CAAC,CAAA;AAC3C;AACA;AACA;AACA,EAAE,OAAO,YAAY,CAAA;AACrB,CAAA;AACA;;;;;;"}
|
package/cjs/reactrouterv3.js
CHANGED
|
@@ -53,7 +53,7 @@ function reactRouterV3Instrumentation(
|
|
|
53
53
|
history.listen(location => {
|
|
54
54
|
if (location.action === 'PUSH' || location.action === 'POP') {
|
|
55
55
|
if (activeTransaction) {
|
|
56
|
-
activeTransaction.
|
|
56
|
+
activeTransaction.end();
|
|
57
57
|
}
|
|
58
58
|
const tags = {
|
|
59
59
|
'routing.instrumentation': 'react-router-v3',
|
package/cjs/reactrouterv3.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactrouterv3.js","sources":["../../src/reactrouterv3.ts"],"sourcesContent":["import { WINDOW } from '@sentry/browser';\nimport type { Primitive, Transaction, TransactionContext, TransactionSource } from '@sentry/types';\n\nimport type { Location, ReactRouterInstrumentation } from './types';\n\n// Many of the types below had to be mocked out to prevent typescript issues\n// these types are required for correct functionality.\n\ntype HistoryV3 = {\n location?: Location;\n listen?(cb: (location: Location) => void): void;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n} & Record<string, any>;\n\nexport type Route = { path?: string; childRoutes?: Route[] };\n\nexport type Match = (\n props: { location: Location; routes: Route[] },\n cb: (error?: Error, _redirectLocation?: Location, renderProps?: { routes?: Route[] }) => void,\n) => void;\n\ntype ReactRouterV3TransactionSource = Extract<TransactionSource, 'url' | 'route'>;\n\n/**\n * Creates routing instrumentation for React Router v3\n * Works for React Router >= 3.2.0 and < 4.0.0\n *\n * @param history object from the `history` library\n * @param routes a list of all routes, should be\n * @param match `Router.match` utility\n */\nexport function reactRouterV3Instrumentation(\n history: HistoryV3,\n routes: Route[],\n match: Match,\n): ReactRouterInstrumentation {\n return (\n startTransaction: (context: TransactionContext) => Transaction | undefined,\n startTransactionOnPageLoad: boolean = true,\n startTransactionOnLocationChange: boolean = true,\n ) => {\n let activeTransaction: Transaction | undefined;\n let prevName: string | undefined;\n\n // Have to use window.location because history.location might not be defined.\n if (startTransactionOnPageLoad && WINDOW && WINDOW.location) {\n normalizeTransactionName(\n routes,\n WINDOW.location as unknown as Location,\n match,\n (localName: string, source: ReactRouterV3TransactionSource = 'url') => {\n prevName = localName;\n activeTransaction = startTransaction({\n name: prevName,\n op: 'pageload',\n origin: 'auto.pageload.react.reactrouterv3',\n tags: {\n 'routing.instrumentation': 'react-router-v3',\n },\n metadata: {\n source,\n },\n });\n },\n );\n }\n\n if (startTransactionOnLocationChange && history.listen) {\n history.listen(location => {\n if (location.action === 'PUSH' || location.action === 'POP') {\n if (activeTransaction) {\n activeTransaction.
|
|
1
|
+
{"version":3,"file":"reactrouterv3.js","sources":["../../src/reactrouterv3.ts"],"sourcesContent":["import { WINDOW } from '@sentry/browser';\nimport type { Primitive, Transaction, TransactionContext, TransactionSource } from '@sentry/types';\n\nimport type { Location, ReactRouterInstrumentation } from './types';\n\n// Many of the types below had to be mocked out to prevent typescript issues\n// these types are required for correct functionality.\n\ntype HistoryV3 = {\n location?: Location;\n listen?(cb: (location: Location) => void): void;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n} & Record<string, any>;\n\nexport type Route = { path?: string; childRoutes?: Route[] };\n\nexport type Match = (\n props: { location: Location; routes: Route[] },\n cb: (error?: Error, _redirectLocation?: Location, renderProps?: { routes?: Route[] }) => void,\n) => void;\n\ntype ReactRouterV3TransactionSource = Extract<TransactionSource, 'url' | 'route'>;\n\n/**\n * Creates routing instrumentation for React Router v3\n * Works for React Router >= 3.2.0 and < 4.0.0\n *\n * @param history object from the `history` library\n * @param routes a list of all routes, should be\n * @param match `Router.match` utility\n */\nexport function reactRouterV3Instrumentation(\n history: HistoryV3,\n routes: Route[],\n match: Match,\n): ReactRouterInstrumentation {\n return (\n startTransaction: (context: TransactionContext) => Transaction | undefined,\n startTransactionOnPageLoad: boolean = true,\n startTransactionOnLocationChange: boolean = true,\n ) => {\n let activeTransaction: Transaction | undefined;\n let prevName: string | undefined;\n\n // Have to use window.location because history.location might not be defined.\n if (startTransactionOnPageLoad && WINDOW && WINDOW.location) {\n normalizeTransactionName(\n routes,\n WINDOW.location as unknown as Location,\n match,\n (localName: string, source: ReactRouterV3TransactionSource = 'url') => {\n prevName = localName;\n activeTransaction = startTransaction({\n name: prevName,\n op: 'pageload',\n origin: 'auto.pageload.react.reactrouterv3',\n tags: {\n 'routing.instrumentation': 'react-router-v3',\n },\n metadata: {\n source,\n },\n });\n },\n );\n }\n\n if (startTransactionOnLocationChange && history.listen) {\n history.listen(location => {\n if (location.action === 'PUSH' || location.action === 'POP') {\n if (activeTransaction) {\n activeTransaction.end();\n }\n const tags: Record<string, Primitive> = {\n 'routing.instrumentation': 'react-router-v3',\n };\n if (prevName) {\n tags.from = prevName;\n }\n normalizeTransactionName(routes, location, match, (localName: string, source: TransactionSource = 'url') => {\n prevName = localName;\n activeTransaction = startTransaction({\n name: prevName,\n op: 'navigation',\n origin: 'auto.navigation.react.reactrouterv3',\n tags,\n metadata: {\n source,\n },\n });\n });\n }\n });\n }\n };\n}\n\n/**\n * Normalize transaction names using `Router.match`\n */\nfunction normalizeTransactionName(\n appRoutes: Route[],\n location: Location,\n match: Match,\n callback: (pathname: string, source?: ReactRouterV3TransactionSource) => void,\n): void {\n let name = location.pathname;\n match(\n {\n location,\n routes: appRoutes,\n },\n (error, _redirectLocation, renderProps) => {\n if (error || !renderProps) {\n return callback(name);\n }\n\n const routePath = getRouteStringFromRoutes(renderProps.routes || []);\n if (routePath.length === 0 || routePath === '/*') {\n return callback(name);\n }\n\n name = routePath;\n return callback(name, 'route');\n },\n );\n}\n\n/**\n * Generate route name from array of routes\n */\nfunction getRouteStringFromRoutes(routes: Route[]): string {\n if (!Array.isArray(routes) || routes.length === 0) {\n return '';\n }\n\n const routesWithPaths: Route[] = routes.filter((route: Route) => !!route.path);\n\n let index = -1;\n for (let x = routesWithPaths.length - 1; x >= 0; x--) {\n const route = routesWithPaths[x];\n if (route.path && route.path.startsWith('/')) {\n index = x;\n break;\n }\n }\n\n return routesWithPaths\n .slice(index)\n .filter(({ path }) => !!path)\n .map(({ path }) => path)\n .join('');\n}\n"],"names":["WINDOW"],"mappings":";;;;AAKA;AACA;;AAiBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,4BAA4B;AAC5C,EAAE,OAAO;AACT,EAAE,MAAM;AACR,EAAE,KAAK;AACP,EAA8B;AAC9B,EAAE,OAAO;AACT,IAAI,gBAAgB;AACpB,IAAI,0BAA0B,GAAY,IAAI;AAC9C,IAAI,gCAAgC,GAAY,IAAI;AACpD,OAAO;AACP,IAAI,IAAI,iBAAiB,CAAA;AACzB,IAAI,IAAI,QAAQ,CAAA;AAChB;AACA;AACA,IAAI,IAAI,0BAA2B,IAAGA,kBAAUA,cAAM,CAAC,QAAQ,EAAE;AACjE,MAAM,wBAAwB;AAC9B,QAAQ,MAAM;AACd,QAAQA,cAAM,CAAC,QAAS;AACxB,QAAQ,KAAK;AACb,QAAQ,CAAC,SAAS,EAAU,MAAM,GAAmC,KAAK,KAAK;AAC/E,UAAU,QAAA,GAAW,SAAS,CAAA;AAC9B,UAAU,iBAAA,G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E,eAAe,CAAC,MAAA,GAAS,CAAC,EAAE,CAAE,IAAG,CAAC,EAAE,CAAC,EAAE,EAAE;AACxD,IAAI,MAAM,KAAM,GAAE,eAAe,CAAC,CAAC,CAAC,CAAA;AACpC,IAAI,IAAI,KAAK,CAAC,QAAQ,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;AAClD,MAAM,KAAA,GAAQ,CAAC,CAAA;AACf,MAAM,MAAK;AACX,KAAI;AACJ,GAAE;AACF;AACA,EAAE,OAAO,eAAA;AACT,KAAK,KAAK,CAAC,KAAK,CAAA;AAChB,KAAK,MAAM,CAAC,CAAC,EAAE,IAAK,EAAC,KAAK,CAAC,CAAC,IAAI,CAAA;AAChC,KAAK,GAAG,CAAC,CAAC,EAAE,IAAK,EAAC,KAAK,IAAI,CAAA;AAC3B,KAAK,IAAI,CAAC,EAAE,CAAC,CAAA;AACb;;;;"}
|
package/cjs/reactrouterv6.js
CHANGED
|
@@ -134,7 +134,9 @@ function updatePageloadTransaction(
|
|
|
134
134
|
: (_matchRoutes(routes, location, basename) );
|
|
135
135
|
|
|
136
136
|
if (activeTransaction && branches) {
|
|
137
|
-
|
|
137
|
+
const [name, source] = getNormalizedName(routes, location, branches, basename);
|
|
138
|
+
activeTransaction.updateName(name);
|
|
139
|
+
activeTransaction.setMetadata({ source });
|
|
138
140
|
}
|
|
139
141
|
}
|
|
140
142
|
|
|
@@ -149,7 +151,7 @@ function handleNavigation(
|
|
|
149
151
|
|
|
150
152
|
if (_startTransactionOnLocationChange && (navigationType === 'PUSH' || navigationType === 'POP') && branches) {
|
|
151
153
|
if (activeTransaction) {
|
|
152
|
-
activeTransaction.
|
|
154
|
+
activeTransaction.end();
|
|
153
155
|
}
|
|
154
156
|
|
|
155
157
|
const [name, source] = getNormalizedName(routes, location, branches, basename);
|
|
@@ -207,7 +209,7 @@ function withSentryReactRouterV6Routing(Routes) {
|
|
|
207
209
|
|
|
208
210
|
// @ts-expect-error Setting more specific React Component typing for `R` generic above
|
|
209
211
|
// will break advanced type inference done by react router params
|
|
210
|
-
return React__namespace.createElement(Routes, { ...props, __self: this, __source: {fileName: _jsxFileName, lineNumber:
|
|
212
|
+
return React__namespace.createElement(Routes, { ...props, __self: this, __source: {fileName: _jsxFileName, lineNumber: 212}} );
|
|
211
213
|
};
|
|
212
214
|
|
|
213
215
|
hoistNonReactStatics__default(SentryRoutes, Routes);
|
|
@@ -262,7 +264,7 @@ function wrapUseRoutes(origUseRoutes) {
|
|
|
262
264
|
|
|
263
265
|
// eslint-disable-next-line react/display-name
|
|
264
266
|
return (routes, locationArg) => {
|
|
265
|
-
return React__namespace.createElement(SentryRoutes, { routes: routes, locationArg: locationArg, __self: this, __source: {fileName: _jsxFileName, lineNumber:
|
|
267
|
+
return React__namespace.createElement(SentryRoutes, { routes: routes, locationArg: locationArg, __self: this, __source: {fileName: _jsxFileName, lineNumber: 269}} );
|
|
266
268
|
};
|
|
267
269
|
}
|
|
268
270
|
|
package/cjs/reactrouterv6.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactrouterv6.js","sources":["../../src/reactrouterv6.tsx"],"sourcesContent":["// Inspired from Donnie McNeal's solution:\n// https://gist.github.com/wontondon/e8c4bdf2888875e4c755712e99279536\n\nimport { WINDOW } from '@sentry/browser';\nimport type { Transaction, TransactionContext, TransactionSource } from '@sentry/types';\nimport { getNumberOfUrlSegments, logger } from '@sentry/utils';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nimport { DEBUG_BUILD } from './debug-build';\nimport type {\n Action,\n AgnosticDataRouteMatch,\n CreateRouterFunction,\n CreateRoutesFromChildren,\n Location,\n MatchRoutes,\n RouteMatch,\n RouteObject,\n Router,\n RouterState,\n UseEffect,\n UseLocation,\n UseNavigationType,\n UseRoutes,\n} from './types';\n\nlet activeTransaction: Transaction | undefined;\n\nlet _useEffect: UseEffect;\nlet _useLocation: UseLocation;\nlet _useNavigationType: UseNavigationType;\nlet _createRoutesFromChildren: CreateRoutesFromChildren;\nlet _matchRoutes: MatchRoutes;\nlet _customStartTransaction: (context: TransactionContext) => Transaction | undefined;\nlet _startTransactionOnLocationChange: boolean;\n\nconst SENTRY_TAGS = {\n 'routing.instrumentation': 'react-router-v6',\n};\n\nexport function reactRouterV6Instrumentation(\n useEffect: UseEffect,\n useLocation: UseLocation,\n useNavigationType: UseNavigationType,\n createRoutesFromChildren: CreateRoutesFromChildren,\n matchRoutes: MatchRoutes,\n) {\n return (\n customStartTransaction: (context: TransactionContext) => Transaction | undefined,\n startTransactionOnPageLoad = true,\n startTransactionOnLocationChange = true,\n ): void => {\n const initPathName = WINDOW && WINDOW.location && WINDOW.location.pathname;\n if (startTransactionOnPageLoad && initPathName) {\n activeTransaction = customStartTransaction({\n name: initPathName,\n op: 'pageload',\n origin: 'auto.pageload.react.reactrouterv6',\n tags: SENTRY_TAGS,\n metadata: {\n source: 'url',\n },\n });\n }\n\n _useEffect = useEffect;\n _useLocation = useLocation;\n _useNavigationType = useNavigationType;\n _matchRoutes = matchRoutes;\n _createRoutesFromChildren = createRoutesFromChildren;\n\n _customStartTransaction = customStartTransaction;\n _startTransactionOnLocationChange = startTransactionOnLocationChange;\n };\n}\n\nfunction getNormalizedName(\n routes: RouteObject[],\n location: Location,\n branches: RouteMatch[],\n basename: string = '',\n): [string, TransactionSource] {\n if (!routes || routes.length === 0) {\n return [location.pathname, 'url'];\n }\n\n let pathBuilder = '';\n if (branches) {\n // eslint-disable-next-line @typescript-eslint/prefer-for-of\n for (let x = 0; x < branches.length; x++) {\n const branch = branches[x];\n const route = branch.route;\n if (route) {\n // Early return if index route\n if (route.index) {\n return [branch.pathname, 'route'];\n }\n\n const path = route.path;\n if (path) {\n const newPath = path[0] === '/' || pathBuilder[pathBuilder.length - 1] === '/' ? path : `/${path}`;\n pathBuilder += newPath;\n\n if (basename + branch.pathname === location.pathname) {\n if (\n // If the route defined on the element is something like\n // <Route path=\"/stores/:storeId/products/:productId\" element={<div>Product</div>} />\n // We should check against the branch.pathname for the number of / seperators\n getNumberOfUrlSegments(pathBuilder) !== getNumberOfUrlSegments(branch.pathname) &&\n // We should not count wildcard operators in the url segments calculation\n pathBuilder.slice(-2) !== '/*'\n ) {\n return [basename + newPath, 'route'];\n }\n return [basename + pathBuilder, 'route'];\n }\n }\n }\n }\n }\n\n return [location.pathname, 'url'];\n}\n\nfunction updatePageloadTransaction(\n location: Location,\n routes: RouteObject[],\n matches?: AgnosticDataRouteMatch,\n basename?: string,\n): void {\n const branches = Array.isArray(matches)\n ? matches\n : (_matchRoutes(routes, location, basename) as unknown as RouteMatch[]);\n\n if (activeTransaction && branches) {\n activeTransaction.setName(...getNormalizedName(routes, location, branches, basename));\n }\n}\n\nfunction handleNavigation(\n location: Location,\n routes: RouteObject[],\n navigationType: Action,\n matches?: AgnosticDataRouteMatch,\n basename?: string,\n): void {\n const branches = Array.isArray(matches) ? matches : _matchRoutes(routes, location, basename);\n\n if (_startTransactionOnLocationChange && (navigationType === 'PUSH' || navigationType === 'POP') && branches) {\n if (activeTransaction) {\n activeTransaction.finish();\n }\n\n const [name, source] = getNormalizedName(routes, location, branches, basename);\n activeTransaction = _customStartTransaction({\n name,\n op: 'navigation',\n origin: 'auto.navigation.react.reactrouterv6',\n tags: SENTRY_TAGS,\n metadata: {\n source,\n },\n });\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function withSentryReactRouterV6Routing<P extends Record<string, any>, R extends React.FC<P>>(Routes: R): R {\n if (\n !_useEffect ||\n !_useLocation ||\n !_useNavigationType ||\n !_createRoutesFromChildren ||\n !_matchRoutes ||\n !_customStartTransaction\n ) {\n DEBUG_BUILD &&\n logger.warn(`reactRouterV6Instrumentation was unable to wrap Routes because of one or more missing parameters.\n useEffect: ${_useEffect}. useLocation: ${_useLocation}. useNavigationType: ${_useNavigationType}.\n createRoutesFromChildren: ${_createRoutesFromChildren}. matchRoutes: ${_matchRoutes}. customStartTransaction: ${_customStartTransaction}.`);\n\n return Routes;\n }\n\n let isMountRenderPass: boolean = true;\n\n const SentryRoutes: React.FC<P> = (props: P) => {\n const location = _useLocation();\n const navigationType = _useNavigationType();\n\n _useEffect(\n () => {\n const routes = _createRoutesFromChildren(props.children) as RouteObject[];\n\n if (isMountRenderPass) {\n updatePageloadTransaction(location, routes);\n isMountRenderPass = false;\n } else {\n handleNavigation(location, routes, navigationType);\n }\n },\n // `props.children` is purpusely not included in the dependency array, because we do not want to re-run this effect\n // when the children change. We only want to start transactions when the location or navigation type change.\n [location, navigationType],\n );\n\n // @ts-expect-error Setting more specific React Component typing for `R` generic above\n // will break advanced type inference done by react router params\n return <Routes {...props} />;\n };\n\n hoistNonReactStatics(SentryRoutes, Routes);\n\n // @ts-expect-error Setting more specific React Component typing for `R` generic above\n // will break advanced type inference done by react router params\n return SentryRoutes;\n}\n\nexport function wrapUseRoutes(origUseRoutes: UseRoutes): UseRoutes {\n if (!_useEffect || !_useLocation || !_useNavigationType || !_matchRoutes || !_customStartTransaction) {\n DEBUG_BUILD &&\n logger.warn(\n 'reactRouterV6Instrumentation was unable to wrap `useRoutes` because of one or more missing parameters.',\n );\n\n return origUseRoutes;\n }\n\n let isMountRenderPass: boolean = true;\n\n const SentryRoutes: React.FC<{\n children?: React.ReactNode;\n routes: RouteObject[];\n locationArg?: Partial<Location> | string;\n }> = (props: { children?: React.ReactNode; routes: RouteObject[]; locationArg?: Partial<Location> | string }) => {\n const { routes, locationArg } = props;\n\n const Routes = origUseRoutes(routes, locationArg);\n\n const location = _useLocation();\n const navigationType = _useNavigationType();\n\n // A value with stable identity to either pick `locationArg` if available or `location` if not\n const stableLocationParam =\n typeof locationArg === 'string' || (locationArg && locationArg.pathname)\n ? (locationArg as { pathname: string })\n : location;\n\n _useEffect(() => {\n const normalizedLocation =\n typeof stableLocationParam === 'string' ? { pathname: stableLocationParam } : stableLocationParam;\n\n if (isMountRenderPass) {\n updatePageloadTransaction(normalizedLocation, routes);\n isMountRenderPass = false;\n } else {\n handleNavigation(normalizedLocation, routes, navigationType);\n }\n }, [navigationType, stableLocationParam]);\n\n return Routes;\n };\n\n // eslint-disable-next-line react/display-name\n return (routes: RouteObject[], locationArg?: Partial<Location> | string): React.ReactElement | null => {\n return <SentryRoutes routes={routes} locationArg={locationArg} />;\n };\n}\n\nexport function wrapCreateBrowserRouter<\n TState extends RouterState = RouterState,\n TRouter extends Router<TState> = Router<TState>,\n>(createRouterFunction: CreateRouterFunction<TState, TRouter>): CreateRouterFunction<TState, TRouter> {\n // `opts` for createBrowserHistory and createMemoryHistory are different, but also not relevant for us at the moment.\n // `basename` is the only option that is relevant for us, and it is the same for all.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return function (routes: RouteObject[], opts?: Record<string, any> & { basename?: string }): TRouter {\n const router = createRouterFunction(routes, opts);\n const basename = opts && opts.basename;\n\n // The initial load ends when `createBrowserRouter` is called.\n // This is the earliest convenient time to update the transaction name.\n // Callbacks to `router.subscribe` are not called for the initial load.\n if (router.state.historyAction === 'POP' && activeTransaction) {\n updatePageloadTransaction(router.state.location, routes, undefined, basename);\n }\n\n router.subscribe((state: RouterState) => {\n const location = state.location;\n\n if (\n _startTransactionOnLocationChange &&\n (state.historyAction === 'PUSH' || state.historyAction === 'POP') &&\n activeTransaction\n ) {\n handleNavigation(location, routes, state.historyAction, undefined, basename);\n }\n });\n\n return router;\n };\n}\n"],"names":["WINDOW","getNumberOfUrlSegments","DEBUG_BUILD","logger","React","hoistNonReactStatics"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAA,YAAA,GAAA,4FAAA,CAAA;;AA2BA,IAAA,iBAAA,CAAA;AACA;AACA,IAAA,UAAA,CAAA;AACA,IAAA,YAAA,CAAA;AACA,IAAA,kBAAA,CAAA;AACA,IAAA,yBAAA,CAAA;AACA,IAAA,YAAA,CAAA;AACA,IAAA,uBAAA,CAAA;AACA,IAAA,iCAAA,CAAA;AACA;AACA,MAAA,WAAA,GAAA;AACA,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AA,IAAA,KAAA,CAAA,aAAA,KAAA,KAAA,CAAA;AACA,QAAA,iBAAA;AACA,QAAA;AACA,QAAA,gBAAA,CAAA,QAAA,EAAA,MAAA,EAAA,KAAA,CAAA,aAAA,EAAA,SAAA,EAAA,QAAA,CAAA,CAAA;AACA,OAAA;AACA,KAAA,CAAA,CAAA;AACA;AACA,IAAA,OAAA,MAAA,CAAA;AACA,GAAA,CAAA;AACA;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"reactrouterv6.js","sources":["../../src/reactrouterv6.tsx"],"sourcesContent":["// Inspired from Donnie McNeal's solution:\n// https://gist.github.com/wontondon/e8c4bdf2888875e4c755712e99279536\n\nimport { WINDOW } from '@sentry/browser';\nimport type { Transaction, TransactionContext, TransactionSource } from '@sentry/types';\nimport { getNumberOfUrlSegments, logger } from '@sentry/utils';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nimport { DEBUG_BUILD } from './debug-build';\nimport type {\n Action,\n AgnosticDataRouteMatch,\n CreateRouterFunction,\n CreateRoutesFromChildren,\n Location,\n MatchRoutes,\n RouteMatch,\n RouteObject,\n Router,\n RouterState,\n UseEffect,\n UseLocation,\n UseNavigationType,\n UseRoutes,\n} from './types';\n\nlet activeTransaction: Transaction | undefined;\n\nlet _useEffect: UseEffect;\nlet _useLocation: UseLocation;\nlet _useNavigationType: UseNavigationType;\nlet _createRoutesFromChildren: CreateRoutesFromChildren;\nlet _matchRoutes: MatchRoutes;\nlet _customStartTransaction: (context: TransactionContext) => Transaction | undefined;\nlet _startTransactionOnLocationChange: boolean;\n\nconst SENTRY_TAGS = {\n 'routing.instrumentation': 'react-router-v6',\n};\n\nexport function reactRouterV6Instrumentation(\n useEffect: UseEffect,\n useLocation: UseLocation,\n useNavigationType: UseNavigationType,\n createRoutesFromChildren: CreateRoutesFromChildren,\n matchRoutes: MatchRoutes,\n) {\n return (\n customStartTransaction: (context: TransactionContext) => Transaction | undefined,\n startTransactionOnPageLoad = true,\n startTransactionOnLocationChange = true,\n ): void => {\n const initPathName = WINDOW && WINDOW.location && WINDOW.location.pathname;\n if (startTransactionOnPageLoad && initPathName) {\n activeTransaction = customStartTransaction({\n name: initPathName,\n op: 'pageload',\n origin: 'auto.pageload.react.reactrouterv6',\n tags: SENTRY_TAGS,\n metadata: {\n source: 'url',\n },\n });\n }\n\n _useEffect = useEffect;\n _useLocation = useLocation;\n _useNavigationType = useNavigationType;\n _matchRoutes = matchRoutes;\n _createRoutesFromChildren = createRoutesFromChildren;\n\n _customStartTransaction = customStartTransaction;\n _startTransactionOnLocationChange = startTransactionOnLocationChange;\n };\n}\n\nfunction getNormalizedName(\n routes: RouteObject[],\n location: Location,\n branches: RouteMatch[],\n basename: string = '',\n): [string, TransactionSource] {\n if (!routes || routes.length === 0) {\n return [location.pathname, 'url'];\n }\n\n let pathBuilder = '';\n if (branches) {\n // eslint-disable-next-line @typescript-eslint/prefer-for-of\n for (let x = 0; x < branches.length; x++) {\n const branch = branches[x];\n const route = branch.route;\n if (route) {\n // Early return if index route\n if (route.index) {\n return [branch.pathname, 'route'];\n }\n\n const path = route.path;\n if (path) {\n const newPath = path[0] === '/' || pathBuilder[pathBuilder.length - 1] === '/' ? path : `/${path}`;\n pathBuilder += newPath;\n\n if (basename + branch.pathname === location.pathname) {\n if (\n // If the route defined on the element is something like\n // <Route path=\"/stores/:storeId/products/:productId\" element={<div>Product</div>} />\n // We should check against the branch.pathname for the number of / seperators\n getNumberOfUrlSegments(pathBuilder) !== getNumberOfUrlSegments(branch.pathname) &&\n // We should not count wildcard operators in the url segments calculation\n pathBuilder.slice(-2) !== '/*'\n ) {\n return [basename + newPath, 'route'];\n }\n return [basename + pathBuilder, 'route'];\n }\n }\n }\n }\n }\n\n return [location.pathname, 'url'];\n}\n\nfunction updatePageloadTransaction(\n location: Location,\n routes: RouteObject[],\n matches?: AgnosticDataRouteMatch,\n basename?: string,\n): void {\n const branches = Array.isArray(matches)\n ? matches\n : (_matchRoutes(routes, location, basename) as unknown as RouteMatch[]);\n\n if (activeTransaction && branches) {\n const [name, source] = getNormalizedName(routes, location, branches, basename);\n activeTransaction.updateName(name);\n activeTransaction.setMetadata({ source });\n }\n}\n\nfunction handleNavigation(\n location: Location,\n routes: RouteObject[],\n navigationType: Action,\n matches?: AgnosticDataRouteMatch,\n basename?: string,\n): void {\n const branches = Array.isArray(matches) ? matches : _matchRoutes(routes, location, basename);\n\n if (_startTransactionOnLocationChange && (navigationType === 'PUSH' || navigationType === 'POP') && branches) {\n if (activeTransaction) {\n activeTransaction.end();\n }\n\n const [name, source] = getNormalizedName(routes, location, branches, basename);\n activeTransaction = _customStartTransaction({\n name,\n op: 'navigation',\n origin: 'auto.navigation.react.reactrouterv6',\n tags: SENTRY_TAGS,\n metadata: {\n source,\n },\n });\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function withSentryReactRouterV6Routing<P extends Record<string, any>, R extends React.FC<P>>(Routes: R): R {\n if (\n !_useEffect ||\n !_useLocation ||\n !_useNavigationType ||\n !_createRoutesFromChildren ||\n !_matchRoutes ||\n !_customStartTransaction\n ) {\n DEBUG_BUILD &&\n logger.warn(`reactRouterV6Instrumentation was unable to wrap Routes because of one or more missing parameters.\n useEffect: ${_useEffect}. useLocation: ${_useLocation}. useNavigationType: ${_useNavigationType}.\n createRoutesFromChildren: ${_createRoutesFromChildren}. matchRoutes: ${_matchRoutes}. customStartTransaction: ${_customStartTransaction}.`);\n\n return Routes;\n }\n\n let isMountRenderPass: boolean = true;\n\n const SentryRoutes: React.FC<P> = (props: P) => {\n const location = _useLocation();\n const navigationType = _useNavigationType();\n\n _useEffect(\n () => {\n const routes = _createRoutesFromChildren(props.children) as RouteObject[];\n\n if (isMountRenderPass) {\n updatePageloadTransaction(location, routes);\n isMountRenderPass = false;\n } else {\n handleNavigation(location, routes, navigationType);\n }\n },\n // `props.children` is purpusely not included in the dependency array, because we do not want to re-run this effect\n // when the children change. We only want to start transactions when the location or navigation type change.\n [location, navigationType],\n );\n\n // @ts-expect-error Setting more specific React Component typing for `R` generic above\n // will break advanced type inference done by react router params\n return <Routes {...props} />;\n };\n\n hoistNonReactStatics(SentryRoutes, Routes);\n\n // @ts-expect-error Setting more specific React Component typing for `R` generic above\n // will break advanced type inference done by react router params\n return SentryRoutes;\n}\n\nexport function wrapUseRoutes(origUseRoutes: UseRoutes): UseRoutes {\n if (!_useEffect || !_useLocation || !_useNavigationType || !_matchRoutes || !_customStartTransaction) {\n DEBUG_BUILD &&\n logger.warn(\n 'reactRouterV6Instrumentation was unable to wrap `useRoutes` because of one or more missing parameters.',\n );\n\n return origUseRoutes;\n }\n\n let isMountRenderPass: boolean = true;\n\n const SentryRoutes: React.FC<{\n children?: React.ReactNode;\n routes: RouteObject[];\n locationArg?: Partial<Location> | string;\n }> = (props: { children?: React.ReactNode; routes: RouteObject[]; locationArg?: Partial<Location> | string }) => {\n const { routes, locationArg } = props;\n\n const Routes = origUseRoutes(routes, locationArg);\n\n const location = _useLocation();\n const navigationType = _useNavigationType();\n\n // A value with stable identity to either pick `locationArg` if available or `location` if not\n const stableLocationParam =\n typeof locationArg === 'string' || (locationArg && locationArg.pathname)\n ? (locationArg as { pathname: string })\n : location;\n\n _useEffect(() => {\n const normalizedLocation =\n typeof stableLocationParam === 'string' ? { pathname: stableLocationParam } : stableLocationParam;\n\n if (isMountRenderPass) {\n updatePageloadTransaction(normalizedLocation, routes);\n isMountRenderPass = false;\n } else {\n handleNavigation(normalizedLocation, routes, navigationType);\n }\n }, [navigationType, stableLocationParam]);\n\n return Routes;\n };\n\n // eslint-disable-next-line react/display-name\n return (routes: RouteObject[], locationArg?: Partial<Location> | string): React.ReactElement | null => {\n return <SentryRoutes routes={routes} locationArg={locationArg} />;\n };\n}\n\nexport function wrapCreateBrowserRouter<\n TState extends RouterState = RouterState,\n TRouter extends Router<TState> = Router<TState>,\n>(createRouterFunction: CreateRouterFunction<TState, TRouter>): CreateRouterFunction<TState, TRouter> {\n // `opts` for createBrowserHistory and createMemoryHistory are different, but also not relevant for us at the moment.\n // `basename` is the only option that is relevant for us, and it is the same for all.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return function (routes: RouteObject[], opts?: Record<string, any> & { basename?: string }): TRouter {\n const router = createRouterFunction(routes, opts);\n const basename = opts && opts.basename;\n\n // The initial load ends when `createBrowserRouter` is called.\n // This is the earliest convenient time to update the transaction name.\n // Callbacks to `router.subscribe` are not called for the initial load.\n if (router.state.historyAction === 'POP' && activeTransaction) {\n updatePageloadTransaction(router.state.location, routes, undefined, basename);\n }\n\n router.subscribe((state: RouterState) => {\n const location = state.location;\n\n if (\n _startTransactionOnLocationChange &&\n (state.historyAction === 'PUSH' || state.historyAction === 'POP') &&\n activeTransaction\n ) {\n handleNavigation(location, routes, state.historyAction, undefined, basename);\n }\n });\n\n return router;\n };\n}\n"],"names":["WINDOW","getNumberOfUrlSegments","DEBUG_BUILD","logger","React","hoistNonReactStatics"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAA,YAAA,GAAA,4FAAA,CAAA;;AA2BA,IAAI,iBAAiB,CAAA;AACrB;AACA,IAAI,UAAU,CAAA;AACd,IAAI,YAAY,CAAA;AAChB,IAAI,kBAAkB,CAAA;AACtB,IAAI,yBAAyB,CAAA;AAC7B,IAAI,YAAY,CAAA;AAChB,IAAI,uBAAuB,CAAA;AAC3B,IAAI,iCAAiC,CAAA;AACrC;AACA,MAAM,cAAc;AACpB,EAAE,yBAAyB,EAAE,iBAAiB;AAC9C,CAAC,CAAA;AACD;AACO,SAAS,4BAA4B;AAC5C,EAAE,SAAS;AACX,EAAE,WAAW;AACb,EAAE,iBAAiB;AACnB,EAAE,wBAAwB;AAC1B,EAAE,WAAW;AACb,EAAE;AACF,EAAE,OAAO;AACT,IAAI,sBAAsB;AAC1B,IAAI,0BAAA,GAA6B,IAAI;AACrC,IAAI,gCAAA,GAAmC,IAAI;AAC3C,OAAa;AACb,IAAI,MAAM,YAAA,GAAeA,cAAA,IAAUA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,CAAA,QAAA,EAAA,MAAA,EAAA,KAAA,CAAA,aAAA,EAAA,SAAA,EAAA,QAAA,CAAA,CAAA;AACA,OAAA;AACA,KAAA,CAAA,CAAA;AACA;AACA,IAAA,OAAA,MAAA,CAAA;AACA,GAAA,CAAA;AACA;;;;;;;"}
|
package/cjs/redux.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redux.js","sources":["../../src/redux.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { addEventProcessor, getClient, getCurrentScope } from '@sentry/browser';\nimport type { Scope } from '@sentry/types';\nimport { addNonEnumerableProperty } from '@sentry/utils';\n\ninterface Action<T = any> {\n type: T;\n}\n\ninterface AnyAction extends Action {\n [extraProps: string]: any;\n}\n\ntype Reducer<S = any, A extends Action = AnyAction> = (state: S | undefined, action: A) => S;\n\ntype Dispatch<A extends Action = AnyAction> = <T extends A>(action: T, ...extraArgs: any[]) => T;\n\ntype ExtendState<State, Extension> = [Extension] extends [never] ? State : State & Extension;\n\ntype Unsubscribe = () => void;\n\ninterface Store<S = any, A extends Action = AnyAction, StateExt = never, Ext = Record<string, unknown>> {\n dispatch: Dispatch<A>;\n getState(): S;\n subscribe(listener: () => void): Unsubscribe;\n replaceReducer<NewState, NewActions extends Action>(\n nextReducer: Reducer<NewState, NewActions>,\n ): Store<ExtendState<NewState, StateExt>, NewActions, StateExt, Ext> & Ext;\n}\n\ndeclare const $CombinedState: unique symbol;\n\ntype CombinedState<S> = { readonly [$CombinedState]?: undefined } & S;\n\ntype PreloadedState<S> = Required<S> extends {\n [$CombinedState]: undefined;\n}\n ? S extends CombinedState<infer S1>\n ? { [K in keyof S1]?: S1[K] extends Record<string, unknown> ? PreloadedState<S1[K]> : S1[K] }\n : never\n : { [K in keyof S]: S[K] extends string | number | boolean | symbol ? S[K] : PreloadedState<S[K]> };\n\ntype StoreEnhancerStoreCreator<Ext = Record<string, unknown>, StateExt = never> = <\n S = any,\n A extends Action = AnyAction,\n>(\n reducer: Reducer<S, A>,\n preloadedState?: PreloadedState<S>,\n) => Store<ExtendState<S, StateExt>, A, StateExt, Ext> & Ext;\n\nexport interface SentryEnhancerOptions<S = any> {\n /**\n * Redux state in attachments or not.\n * @default true\n */\n attachReduxState?: boolean;\n\n /**\n * Transforms the state before attaching it to an event.\n * Use this to remove any private data before sending it to Sentry.\n * Return null to not attach the state.\n */\n stateTransformer(state: S | undefined): (S & any) | null;\n /**\n * Transforms the action before sending it as a breadcrumb.\n * Use this to remove any private data before sending it to Sentry.\n * Return null to not send the breadcrumb.\n */\n actionTransformer(action: AnyAction): AnyAction | null;\n /**\n * Called on every state update, configure the Sentry Scope with the redux state.\n */\n configureScopeWithState?(scope: Scope, state: S): void;\n}\n\nconst ACTION_BREADCRUMB_CATEGORY = 'redux.action';\nconst ACTION_BREADCRUMB_TYPE = 'info';\n\nconst defaultOptions: SentryEnhancerOptions = {\n attachReduxState: true,\n actionTransformer: action => action,\n stateTransformer: state => state || null,\n};\n\n/**\n * Creates an enhancer that would be passed to Redux's createStore to log actions and the latest state to Sentry.\n *\n * @param enhancerOptions Options to pass to the enhancer\n */\nfunction createReduxEnhancer(enhancerOptions?: Partial<SentryEnhancerOptions>): any {\n // Note: We return an any type as to not have type conflicts.\n const options = {\n ...defaultOptions,\n ...enhancerOptions,\n };\n\n return (next: StoreEnhancerStoreCreator): StoreEnhancerStoreCreator =>\n <S = any, A extends Action = AnyAction>(reducer: Reducer<S, A>, initialState?: PreloadedState<S>) => {\n options.attachReduxState &&\n addEventProcessor((event, hint) => {\n try {\n // @ts-expect-error try catch to reduce bundle size\n if (event.type === undefined && event.contexts.state.state.type === 'redux') {\n hint.attachments = [\n ...(hint.attachments || []),\n // @ts-expect-error try catch to reduce bundle size\n { filename: 'redux_state.json', data: JSON.stringify(event.contexts.state.state.value) },\n ];\n }\n } catch (_) {\n // empty\n }\n return event;\n });\n\n const sentryReducer: Reducer<S, A> = (state, action): S => {\n const newState = reducer(state, action);\n\n const scope = getCurrentScope();\n /* Action breadcrumbs */\n const transformedAction = options.actionTransformer(action);\n if (typeof transformedAction !== 'undefined' && transformedAction !== null) {\n scope.addBreadcrumb({\n category: ACTION_BREADCRUMB_CATEGORY,\n data: transformedAction,\n type: ACTION_BREADCRUMB_TYPE,\n });\n }\n\n /* Set latest state to scope */\n const transformedState = options.stateTransformer(newState);\n if (typeof transformedState !== 'undefined' && transformedState !== null) {\n const client = getClient();\n const options = client && client.getOptions();\n const normalizationDepth = (options && options.normalizeDepth) || 3; // default state normalization depth to 3\n\n // Set the normalization depth of the redux state to the configured `normalizeDepth` option or a sane number as a fallback\n const newStateContext = { state: { type: 'redux', value: transformedState } };\n addNonEnumerableProperty(\n newStateContext,\n '__sentry_override_normalization_depth__',\n 3 + // 3 layers for `state.value.transformedState`\n normalizationDepth, // rest for the actual state\n );\n\n scope.setContext('state', newStateContext);\n } else {\n scope.setContext('state', null);\n }\n\n /* Allow user to configure scope with latest state */\n const { configureScopeWithState } = options;\n if (typeof configureScopeWithState === 'function') {\n configureScopeWithState(scope, newState);\n }\n\n return newState;\n };\n\n return next(sentryReducer, initialState);\n };\n}\n\nexport { createReduxEnhancer };\n"],"names":["addEventProcessor","getCurrentScope","getClient","addNonEnumerableProperty"],"mappings":";;;;;AAAA;;AA2EA,
|
|
1
|
+
{"version":3,"file":"redux.js","sources":["../../src/redux.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { addEventProcessor, getClient, getCurrentScope } from '@sentry/browser';\nimport type { Scope } from '@sentry/types';\nimport { addNonEnumerableProperty } from '@sentry/utils';\n\ninterface Action<T = any> {\n type: T;\n}\n\ninterface AnyAction extends Action {\n [extraProps: string]: any;\n}\n\ntype Reducer<S = any, A extends Action = AnyAction> = (state: S | undefined, action: A) => S;\n\ntype Dispatch<A extends Action = AnyAction> = <T extends A>(action: T, ...extraArgs: any[]) => T;\n\ntype ExtendState<State, Extension> = [Extension] extends [never] ? State : State & Extension;\n\ntype Unsubscribe = () => void;\n\ninterface Store<S = any, A extends Action = AnyAction, StateExt = never, Ext = Record<string, unknown>> {\n dispatch: Dispatch<A>;\n getState(): S;\n subscribe(listener: () => void): Unsubscribe;\n replaceReducer<NewState, NewActions extends Action>(\n nextReducer: Reducer<NewState, NewActions>,\n ): Store<ExtendState<NewState, StateExt>, NewActions, StateExt, Ext> & Ext;\n}\n\ndeclare const $CombinedState: unique symbol;\n\ntype CombinedState<S> = { readonly [$CombinedState]?: undefined } & S;\n\ntype PreloadedState<S> = Required<S> extends {\n [$CombinedState]: undefined;\n}\n ? S extends CombinedState<infer S1>\n ? { [K in keyof S1]?: S1[K] extends Record<string, unknown> ? PreloadedState<S1[K]> : S1[K] }\n : never\n : { [K in keyof S]: S[K] extends string | number | boolean | symbol ? S[K] : PreloadedState<S[K]> };\n\ntype StoreEnhancerStoreCreator<Ext = Record<string, unknown>, StateExt = never> = <\n S = any,\n A extends Action = AnyAction,\n>(\n reducer: Reducer<S, A>,\n preloadedState?: PreloadedState<S>,\n) => Store<ExtendState<S, StateExt>, A, StateExt, Ext> & Ext;\n\nexport interface SentryEnhancerOptions<S = any> {\n /**\n * Redux state in attachments or not.\n * @default true\n */\n attachReduxState?: boolean;\n\n /**\n * Transforms the state before attaching it to an event.\n * Use this to remove any private data before sending it to Sentry.\n * Return null to not attach the state.\n */\n stateTransformer(state: S | undefined): (S & any) | null;\n /**\n * Transforms the action before sending it as a breadcrumb.\n * Use this to remove any private data before sending it to Sentry.\n * Return null to not send the breadcrumb.\n */\n actionTransformer(action: AnyAction): AnyAction | null;\n /**\n * Called on every state update, configure the Sentry Scope with the redux state.\n */\n configureScopeWithState?(scope: Scope, state: S): void;\n}\n\nconst ACTION_BREADCRUMB_CATEGORY = 'redux.action';\nconst ACTION_BREADCRUMB_TYPE = 'info';\n\nconst defaultOptions: SentryEnhancerOptions = {\n attachReduxState: true,\n actionTransformer: action => action,\n stateTransformer: state => state || null,\n};\n\n/**\n * Creates an enhancer that would be passed to Redux's createStore to log actions and the latest state to Sentry.\n *\n * @param enhancerOptions Options to pass to the enhancer\n */\nfunction createReduxEnhancer(enhancerOptions?: Partial<SentryEnhancerOptions>): any {\n // Note: We return an any type as to not have type conflicts.\n const options = {\n ...defaultOptions,\n ...enhancerOptions,\n };\n\n return (next: StoreEnhancerStoreCreator): StoreEnhancerStoreCreator =>\n <S = any, A extends Action = AnyAction>(reducer: Reducer<S, A>, initialState?: PreloadedState<S>) => {\n options.attachReduxState &&\n addEventProcessor((event, hint) => {\n try {\n // @ts-expect-error try catch to reduce bundle size\n if (event.type === undefined && event.contexts.state.state.type === 'redux') {\n hint.attachments = [\n ...(hint.attachments || []),\n // @ts-expect-error try catch to reduce bundle size\n { filename: 'redux_state.json', data: JSON.stringify(event.contexts.state.state.value) },\n ];\n }\n } catch (_) {\n // empty\n }\n return event;\n });\n\n const sentryReducer: Reducer<S, A> = (state, action): S => {\n const newState = reducer(state, action);\n\n const scope = getCurrentScope();\n /* Action breadcrumbs */\n const transformedAction = options.actionTransformer(action);\n if (typeof transformedAction !== 'undefined' && transformedAction !== null) {\n scope.addBreadcrumb({\n category: ACTION_BREADCRUMB_CATEGORY,\n data: transformedAction,\n type: ACTION_BREADCRUMB_TYPE,\n });\n }\n\n /* Set latest state to scope */\n const transformedState = options.stateTransformer(newState);\n if (typeof transformedState !== 'undefined' && transformedState !== null) {\n const client = getClient();\n const options = client && client.getOptions();\n const normalizationDepth = (options && options.normalizeDepth) || 3; // default state normalization depth to 3\n\n // Set the normalization depth of the redux state to the configured `normalizeDepth` option or a sane number as a fallback\n const newStateContext = { state: { type: 'redux', value: transformedState } };\n addNonEnumerableProperty(\n newStateContext,\n '__sentry_override_normalization_depth__',\n 3 + // 3 layers for `state.value.transformedState`\n normalizationDepth, // rest for the actual state\n );\n\n scope.setContext('state', newStateContext);\n } else {\n scope.setContext('state', null);\n }\n\n /* Allow user to configure scope with latest state */\n const { configureScopeWithState } = options;\n if (typeof configureScopeWithState === 'function') {\n configureScopeWithState(scope, newState);\n }\n\n return newState;\n };\n\n return next(sentryReducer, initialState);\n };\n}\n\nexport { createReduxEnhancer };\n"],"names":["addEventProcessor","getCurrentScope","getClient","addNonEnumerableProperty"],"mappings":";;;;;AAAA;;AA2EA,MAAM,0BAAA,GAA6B,cAAc,CAAA;AACjD,MAAM,sBAAA,GAAyB,MAAM,CAAA;AACrC;AACA,MAAM,cAAc,GAA0B;AAC9C,EAAE,gBAAgB,EAAE,IAAI;AACxB,EAAE,iBAAiB,EAAE,MAAO,IAAG,MAAM;AACrC,EAAE,gBAAgB,EAAE,KAAA,IAAS,KAAA,IAAS,IAAI;AAC1C,CAAC,CAAA;AACD;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,mBAAmB,CAAC,eAAe,EAAwC;AACpF;AACA,EAAE,MAAM,UAAU;AAClB,IAAI,GAAG,cAAc;AACrB,IAAI,GAAG,eAAe;AACtB,GAAG,CAAA;AACH;AACA,EAAE,OAAO,CAAC,IAAI;AACd,IAAI,CAAwC,OAAO,EAAiB,YAAY,KAAyB;AACzG,MAAM,OAAO,CAAC,gBAAiB;AAC/B,QAAQA,yBAAiB,CAAC,CAAC,KAAK,EAAE,IAAI,KAAK;AAC3C,UAAU,IAAI;AACd;AACA,YAAY,IAAI,KAAK,CAAC,IAAK,KAAI,aAAa,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,IAAK,KAAI,OAAO,EAAE;AACzF,cAAc,IAAI,CAAC,WAAA,GAAc;AACjC,gBAAgB,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;AAC3C;AACA,gBAAgB,EAAE,QAAQ,EAAE,kBAAkB,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAA,EAAG;AACxG,eAAe,CAAA;AACf,aAAY;AACZ,WAAY,CAAA,OAAO,CAAC,EAAE;AACtB;AACA,WAAU;AACV,UAAU,OAAO,KAAK,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