@sentry/react 8.5.0 → 8.7.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.
@@ -0,0 +1,120 @@
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
+
3
+ const browser = require('@sentry/browser');
4
+ const core = require('@sentry/core');
5
+
6
+ /**
7
+ * A custom browser tracing integration for TanStack Router.
8
+ *
9
+ * The minimum compatible version of `@tanstack/router` is `1.34.5`.
10
+ *
11
+ * @param router A TanStack Router `Router` instance that should be used for routing instrumentation.
12
+ * @param options Sentry browser tracing configuration.
13
+ */
14
+ function tanstackRouterBrowserTracingIntegration(
15
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
+ router, // This is `any` because we don't want any type mismatches if TanStack Router changes their types
17
+ options = {},
18
+ ) {
19
+ const castRouterInstance = router;
20
+
21
+ const browserTracingIntegrationInstance = browser.browserTracingIntegration({
22
+ ...options,
23
+ instrumentNavigation: false,
24
+ instrumentPageLoad: false,
25
+ });
26
+
27
+ const { instrumentPageLoad = true, instrumentNavigation = true } = options;
28
+
29
+ return {
30
+ ...browserTracingIntegrationInstance,
31
+ afterAllSetup(client) {
32
+ browserTracingIntegrationInstance.afterAllSetup(client);
33
+
34
+ const initialWindowLocation = browser.WINDOW.location;
35
+ if (instrumentPageLoad && initialWindowLocation) {
36
+ const matchedRoutes = castRouterInstance.matchRoutes(
37
+ initialWindowLocation.pathname,
38
+ initialWindowLocation.search,
39
+ { preload: false, throwOnError: false },
40
+ );
41
+
42
+ const lastMatch = matchedRoutes[matchedRoutes.length - 1];
43
+
44
+ browser.startBrowserTracingPageLoadSpan(client, {
45
+ name: lastMatch ? lastMatch.routeId : initialWindowLocation.pathname,
46
+ attributes: {
47
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'pageload',
48
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.pageload.react.tanstack_router',
49
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: lastMatch ? 'route' : 'url',
50
+ ...routeMatchToParamSpanAttributes(lastMatch),
51
+ },
52
+ });
53
+ }
54
+
55
+ if (instrumentNavigation) {
56
+ // The onBeforeNavigate hook is called at the very beginning of a navigation and is only called once per navigation, even when the user is redirected
57
+ castRouterInstance.subscribe('onBeforeNavigate', onBeforeNavigateArgs => {
58
+ // onBeforeNavigate is called during pageloads. We can avoid creating navigation spans by comparing the states of the to and from arguments.
59
+ if (onBeforeNavigateArgs.toLocation.state === onBeforeNavigateArgs.fromLocation.state) {
60
+ return;
61
+ }
62
+
63
+ const onResolvedMatchedRoutes = castRouterInstance.matchRoutes(
64
+ onBeforeNavigateArgs.toLocation.pathname,
65
+ onBeforeNavigateArgs.toLocation.search,
66
+ { preload: false, throwOnError: false },
67
+ );
68
+
69
+ const onBeforeNavigateLastMatch = onResolvedMatchedRoutes[onResolvedMatchedRoutes.length - 1];
70
+
71
+ const navigationLocation = browser.WINDOW.location;
72
+ const navigationSpan = browser.startBrowserTracingNavigationSpan(client, {
73
+ name: onBeforeNavigateLastMatch ? onBeforeNavigateLastMatch.routeId : navigationLocation.pathname,
74
+ attributes: {
75
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',
76
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.react.tanstack_router',
77
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: onBeforeNavigateLastMatch ? 'route' : 'url',
78
+ },
79
+ });
80
+
81
+ // In case the user is redirected during navigation we want to update the span with the right value.
82
+ const unsubscribeOnResolved = castRouterInstance.subscribe('onResolved', onResolvedArgs => {
83
+ unsubscribeOnResolved();
84
+ if (navigationSpan) {
85
+ const onResolvedMatchedRoutes = castRouterInstance.matchRoutes(
86
+ onResolvedArgs.toLocation.pathname,
87
+ onResolvedArgs.toLocation.search,
88
+ { preload: false, throwOnError: false },
89
+ );
90
+
91
+ const onResolvedLastMatch = onResolvedMatchedRoutes[onResolvedMatchedRoutes.length - 1];
92
+
93
+ if (onResolvedLastMatch) {
94
+ navigationSpan.updateName(onResolvedLastMatch.routeId);
95
+ navigationSpan.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');
96
+ navigationSpan.setAttributes(routeMatchToParamSpanAttributes(onResolvedLastMatch));
97
+ }
98
+ }
99
+ });
100
+ });
101
+ }
102
+ },
103
+ };
104
+ }
105
+
106
+ function routeMatchToParamSpanAttributes(match) {
107
+ if (!match) {
108
+ return {};
109
+ }
110
+
111
+ const paramAttributes = {};
112
+ for (const key of Object.keys(match.params)) {
113
+ paramAttributes[`url.path.params.${key}`] = match.params[key];
114
+ }
115
+
116
+ return paramAttributes;
117
+ }
118
+
119
+ exports.tanstackRouterBrowserTracingIntegration = tanstackRouterBrowserTracingIntegration;
120
+ //# sourceMappingURL=tanstackrouter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tanstackrouter.js","sources":["../../src/tanstackrouter.ts"],"sourcesContent":["import { WINDOW, startBrowserTracingNavigationSpan, startBrowserTracingPageLoadSpan } from '@sentry/browser';\nimport {\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n} from '@sentry/core';\n\nimport { browserTracingIntegration as originalBrowserTracingIntegration } from '@sentry/browser';\nimport type { Integration } from '@sentry/types';\nimport type { VendoredTanstackRouter, VendoredTanstackRouterRouteMatch } from './vendor/tanstackrouter-types';\n\n/**\n * A custom browser tracing integration for TanStack Router.\n *\n * The minimum compatible version of `@tanstack/router` is `1.34.5`.\n *\n * @param router A TanStack Router `Router` instance that should be used for routing instrumentation.\n * @param options Sentry browser tracing configuration.\n */\nexport function tanstackRouterBrowserTracingIntegration(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n router: any, // This is `any` because we don't want any type mismatches if TanStack Router changes their types\n options: Parameters<typeof originalBrowserTracingIntegration>[0] = {},\n): Integration {\n const castRouterInstance: VendoredTanstackRouter = router;\n\n const browserTracingIntegrationInstance = originalBrowserTracingIntegration({\n ...options,\n instrumentNavigation: false,\n instrumentPageLoad: false,\n });\n\n const { instrumentPageLoad = true, instrumentNavigation = true } = options;\n\n return {\n ...browserTracingIntegrationInstance,\n afterAllSetup(client) {\n browserTracingIntegrationInstance.afterAllSetup(client);\n\n const initialWindowLocation = WINDOW.location;\n if (instrumentPageLoad && initialWindowLocation) {\n const matchedRoutes = castRouterInstance.matchRoutes(\n initialWindowLocation.pathname,\n initialWindowLocation.search,\n { preload: false, throwOnError: false },\n );\n\n const lastMatch = matchedRoutes[matchedRoutes.length - 1];\n\n startBrowserTracingPageLoadSpan(client, {\n name: lastMatch ? lastMatch.routeId : initialWindowLocation.pathname,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'pageload',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.pageload.react.tanstack_router',\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: lastMatch ? 'route' : 'url',\n ...routeMatchToParamSpanAttributes(lastMatch),\n },\n });\n }\n\n if (instrumentNavigation) {\n // The onBeforeNavigate hook is called at the very beginning of a navigation and is only called once per navigation, even when the user is redirected\n castRouterInstance.subscribe('onBeforeNavigate', onBeforeNavigateArgs => {\n // onBeforeNavigate is called during pageloads. We can avoid creating navigation spans by comparing the states of the to and from arguments.\n if (onBeforeNavigateArgs.toLocation.state === onBeforeNavigateArgs.fromLocation.state) {\n return;\n }\n\n const onResolvedMatchedRoutes = castRouterInstance.matchRoutes(\n onBeforeNavigateArgs.toLocation.pathname,\n onBeforeNavigateArgs.toLocation.search,\n { preload: false, throwOnError: false },\n );\n\n const onBeforeNavigateLastMatch = onResolvedMatchedRoutes[onResolvedMatchedRoutes.length - 1];\n\n const navigationLocation = WINDOW.location;\n const navigationSpan = startBrowserTracingNavigationSpan(client, {\n name: onBeforeNavigateLastMatch ? onBeforeNavigateLastMatch.routeId : navigationLocation.pathname,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.react.tanstack_router',\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: onBeforeNavigateLastMatch ? 'route' : 'url',\n },\n });\n\n // In case the user is redirected during navigation we want to update the span with the right value.\n const unsubscribeOnResolved = castRouterInstance.subscribe('onResolved', onResolvedArgs => {\n unsubscribeOnResolved();\n if (navigationSpan) {\n const onResolvedMatchedRoutes = castRouterInstance.matchRoutes(\n onResolvedArgs.toLocation.pathname,\n onResolvedArgs.toLocation.search,\n { preload: false, throwOnError: false },\n );\n\n const onResolvedLastMatch = onResolvedMatchedRoutes[onResolvedMatchedRoutes.length - 1];\n\n if (onResolvedLastMatch) {\n navigationSpan.updateName(onResolvedLastMatch.routeId);\n navigationSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');\n navigationSpan.setAttributes(routeMatchToParamSpanAttributes(onResolvedLastMatch));\n }\n }\n });\n });\n }\n },\n };\n}\n\nfunction routeMatchToParamSpanAttributes(match: VendoredTanstackRouterRouteMatch | undefined): Record<string, string> {\n if (!match) {\n return {};\n }\n\n const paramAttributes: Record<string, string> = {};\n for (const key of Object.keys(match.params)) {\n paramAttributes[`url.path.params.${key}`] = match.params[key];\n }\n\n return paramAttributes;\n}\n"],"names":["originalBrowserTracingIntegration","WINDOW","startBrowserTracingPageLoadSpan","SEMANTIC_ATTRIBUTE_SENTRY_OP","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","startBrowserTracingNavigationSpan"],"mappings":";;;;;AAWA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,uCAAuC;AACvD;AACA,EAAE,MAAM;AACR,EAAE,OAAO,GAA4D,EAAE;AACvE,EAAe;AACf,EAAE,MAAM,kBAAk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AAU,CAAC,MAAM;AAChD,gBAAgB,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,OAAO;AACvD,eAAe,CAAA;AACf;AACA,cAAc,MAAM,mBAAoB,GAAE,uBAAuB,CAAC,uBAAuB,CAAC,MAAA,GAAS,CAAC,CAAC,CAAA;AACrG;AACA,cAAc,IAAI,mBAAmB,EAAE;AACvC,gBAAgB,cAAc,CAAC,UAAU,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAA;AACtE,gBAAgB,cAAc,CAAC,YAAY,CAACA,qCAAgC,EAAE,OAAO,CAAC,CAAA;AACtF,gBAAgB,cAAc,CAAC,aAAa,CAAC,+BAA+B,CAAC,mBAAmB,CAAC,CAAC,CAAA;AAClG,eAAc;AACd,aAAY;AACZ,WAAW,CAAC,CAAA;AACZ,SAAS,CAAC,CAAA;AACV,OAAM;AACN,KAAK;AACL,GAAG,CAAA;AACH,CAAA;AACA;AACA,SAAS,+BAA+B,CAAC,KAAK,EAAwE;AACtH,EAAE,IAAI,CAAC,KAAK,EAAE;AACd,IAAI,OAAO,EAAE,CAAA;AACb,GAAE;AACF;AACA,EAAE,MAAM,eAAe,GAA2B,EAAE,CAAA;AACpD,EAAE,KAAK,MAAM,GAAA,IAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE;AAC/C,IAAI,eAAe,CAAC,CAAC,gBAAgB,EAAE,GAAG,CAAC,CAAA,CAAA,GAAA,KAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA;AACA,GAAA;AACA;AACA,EAAA,OAAA,eAAA,CAAA;AACA;;;;"}
package/esm/error.js ADDED
@@ -0,0 +1,107 @@
1
+ import { captureException } from '@sentry/browser';
2
+ import { isError } from '@sentry/utils';
3
+ import { version } from 'react';
4
+
5
+ /**
6
+ * See if React major version is 17+ by parsing version string.
7
+ */
8
+ function isAtLeastReact17(reactVersion) {
9
+ const reactMajor = reactVersion.match(/^([^.]+)/);
10
+ return reactMajor !== null && parseInt(reactMajor[0]) >= 17;
11
+ }
12
+
13
+ /**
14
+ * Recurse through `error.cause` chain to set cause on an error.
15
+ */
16
+ function setCause(error, cause) {
17
+ const seenErrors = new WeakSet();
18
+
19
+ function recurse(error, cause) {
20
+ // If we've already seen the error, there is a recursive loop somewhere in the error's
21
+ // cause chain. Let's just bail out then to prevent a stack overflow.
22
+ if (seenErrors.has(error)) {
23
+ return;
24
+ }
25
+ if (error.cause) {
26
+ seenErrors.add(error);
27
+ return recurse(error.cause, cause);
28
+ }
29
+ error.cause = cause;
30
+ }
31
+
32
+ recurse(error, cause);
33
+ }
34
+
35
+ /**
36
+ * Captures an error that was thrown by a React ErrorBoundary or React root.
37
+ *
38
+ * @param error The error to capture.
39
+ * @param errorInfo The errorInfo provided by React.
40
+ * @param hint Optional additional data to attach to the Sentry event.
41
+ * @returns the id of the captured Sentry event.
42
+ */
43
+ function captureReactException(
44
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
45
+ error,
46
+ { componentStack },
47
+ hint,
48
+ ) {
49
+ // If on React version >= 17, create stack trace from componentStack param and links
50
+ // to to the original error using `error.cause` otherwise relies on error param for stacktrace.
51
+ // Linking errors requires the `LinkedErrors` integration be enabled.
52
+ // See: https://reactjs.org/blog/2020/08/10/react-v17-rc.html#native-component-stacks
53
+ //
54
+ // Although `componentDidCatch` is typed to accept an `Error` object, it can also be invoked
55
+ // with non-error objects. This is why we need to check if the error is an error-like object.
56
+ // See: https://github.com/getsentry/sentry-javascript/issues/6167
57
+ if (isAtLeastReact17(version) && isError(error) && componentStack) {
58
+ const errorBoundaryError = new Error(error.message);
59
+ errorBoundaryError.name = `React ErrorBoundary ${error.name}`;
60
+ errorBoundaryError.stack = componentStack;
61
+
62
+ // Using the `LinkedErrors` integration to link the errors together.
63
+ setCause(error, errorBoundaryError);
64
+ }
65
+
66
+ return captureException(error, {
67
+ ...hint,
68
+ captureContext: {
69
+ contexts: { react: { componentStack } },
70
+ },
71
+ });
72
+ }
73
+
74
+ /**
75
+ * Creates an error handler that can be used with the `onCaughtError`, `onUncaughtError`,
76
+ * and `onRecoverableError` options in `createRoot` and `hydrateRoot` React DOM methods.
77
+ *
78
+ * @param callback An optional callback that will be called after the error is captured.
79
+ * Use this to add custom handling for errors.
80
+ *
81
+ * @example
82
+ *
83
+ * ```JavaScript
84
+ * const root = createRoot(container, {
85
+ * onCaughtError: Sentry.reactErrorHandler(),
86
+ * onUncaughtError: Sentry.reactErrorHandler((error, errorInfo) => {
87
+ * console.warn('Caught error', error, errorInfo.componentStack);
88
+ * });
89
+ * });
90
+ * ```
91
+ */
92
+ function reactErrorHandler(
93
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
94
+ callback,
95
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
96
+ ) {
97
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
98
+ return (error, errorInfo) => {
99
+ const eventId = captureReactException(error, errorInfo);
100
+ if (callback) {
101
+ callback(error, errorInfo, eventId);
102
+ }
103
+ };
104
+ }
105
+
106
+ export { captureReactException, isAtLeastReact17, reactErrorHandler, setCause };
107
+ //# sourceMappingURL=error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","sources":["../../src/error.ts"],"sourcesContent":["import { captureException } from '@sentry/browser';\nimport type { EventHint } from '@sentry/types';\nimport { isError } from '@sentry/utils';\nimport { version } from 'react';\nimport type { ErrorInfo } from 'react';\n\n/**\n * See if React major version is 17+ by parsing version string.\n */\nexport function isAtLeastReact17(reactVersion: string): boolean {\n const reactMajor = reactVersion.match(/^([^.]+)/);\n return reactMajor !== null && parseInt(reactMajor[0]) >= 17;\n}\n\n/**\n * Recurse through `error.cause` chain to set cause on an error.\n */\nexport function setCause(error: Error & { cause?: Error }, cause: Error): void {\n const seenErrors = new WeakSet();\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.add(error);\n return recurse(error.cause, cause);\n }\n error.cause = cause;\n }\n\n recurse(error, cause);\n}\n\n/**\n * Captures an error that was thrown by a React ErrorBoundary or React root.\n *\n * @param error The error to capture.\n * @param errorInfo The errorInfo provided by React.\n * @param hint Optional additional data to attach to the Sentry event.\n * @returns the id of the captured Sentry event.\n */\nexport function captureReactException(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n error: any,\n { componentStack }: ErrorInfo,\n hint?: EventHint,\n): string {\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(version) && isError(error) && componentStack) {\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 return captureException(error, {\n ...hint,\n captureContext: {\n contexts: { react: { componentStack } },\n },\n });\n}\n\n/**\n * Creates an error handler that can be used with the `onCaughtError`, `onUncaughtError`,\n * and `onRecoverableError` options in `createRoot` and `hydrateRoot` React DOM methods.\n *\n * @param callback An optional callback that will be called after the error is captured.\n * Use this to add custom handling for errors.\n *\n * @example\n *\n * ```JavaScript\n * const root = createRoot(container, {\n * onCaughtError: Sentry.reactErrorHandler(),\n * onUncaughtError: Sentry.reactErrorHandler((error, errorInfo) => {\n * console.warn('Caught error', error, errorInfo.componentStack);\n * });\n * });\n * ```\n */\nexport function reactErrorHandler(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n callback?: (error: any, errorInfo: ErrorInfo, eventId: string) => void,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): (error: any, errorInfo: ErrorInfo) => void {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return (error: any, errorInfo: ErrorInfo) => {\n const eventId = captureReactException(error, errorInfo);\n if (callback) {\n callback(error, errorInfo, eventId);\n }\n };\n}\n"],"names":[],"mappings":";;;;AAMA;AACA;AACA;AACO,SAAS,gBAAgB,CAAC,YAAY,EAAmB;AAChE,EAAE,MAAM,aAAa,YAAY,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;AACnD,EAAE,OAAO,UAAA,KAAe,IAAA,IAAQ,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA,IAAK,EAAE,CAAA;AAC7D,CAAA;AACA;AACA;AACA;AACA;AACO,SAAS,QAAQ,CAAC,KAAK,EAA6B,KAAK,EAAe;AAC/E,EAAE,MAAM,UAAW,GAAE,IAAI,OAAO,EAAE,CAAA;AAClC;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,CAAC,CAAA;AAC3B,MAAM,OAAO,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;AACxC,KAAI;AACJ,IAAI,KAAK,CAAC,KAAM,GAAE,KAAK,CAAA;AACvB,GAAE;AACF;AACA,EAAE,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;AACvB,CAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,qBAAqB;AACrC;AACA,EAAE,KAAK;AACP,EAAE,EAAE,gBAAgB;AACpB,EAAE,IAAI;AACN,EAAU;AACV;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,EAAE,IAAI,gBAAgB,CAAC,OAAO,CAAA,IAAK,OAAO,CAAC,KAAK,CAAE,IAAG,cAAc,EAAE;AACrE,IAAI,MAAM,qBAAqB,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;AACvD,IAAI,kBAAkB,CAAC,IAAA,GAAO,CAAC,oBAAoB,EAAE,KAAK,CAAC,IAAI,CAAC,CAAA,CAAA;AACA,IAAA,kBAAA,CAAA,KAAA,GAAA,cAAA,CAAA;AACA;AACA;AACA,IAAA,QAAA,CAAA,KAAA,EAAA,kBAAA,CAAA,CAAA;AACA,GAAA;AACA;AACA,EAAA,OAAA,gBAAA,CAAA,KAAA,EAAA;AACA,IAAA,GAAA,IAAA;AACA,IAAA,cAAA,EAAA;AACA,MAAA,QAAA,EAAA,EAAA,KAAA,EAAA,EAAA,cAAA,EAAA,EAAA;AACA,KAAA;AACA,GAAA,CAAA,CAAA;AACA,CAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAA,iBAAA;AACA;AACA,EAAA,QAAA;AACA;AACA,EAAA;AACA;AACA,EAAA,OAAA,CAAA,KAAA,EAAA,SAAA,KAAA;AACA,IAAA,MAAA,OAAA,GAAA,qBAAA,CAAA,KAAA,EAAA,SAAA,CAAA,CAAA;AACA,IAAA,IAAA,QAAA,EAAA;AACA,MAAA,QAAA,CAAA,KAAA,EAAA,SAAA,EAAA,OAAA,CAAA,CAAA;AACA,KAAA;AACA,GAAA,CAAA;AACA;;;;"}
@@ -1,14 +1,10 @@
1
1
  import { jsx } from 'react/jsx-runtime';
2
- import { getClient, showReportDialog, withScope, captureException } from '@sentry/browser';
3
- import { isError, logger } from '@sentry/utils';
2
+ import { getClient, showReportDialog, withScope } from '@sentry/browser';
3
+ import { logger } from '@sentry/utils';
4
4
  import hoistNonReactStatics from 'hoist-non-react-statics';
5
5
  import * as React from 'react';
6
6
  import { DEBUG_BUILD } from './debug-build.js';
7
-
8
- function isAtLeastReact17(version) {
9
- const major = version.match(/^([^.]+)/);
10
- return major !== null && parseInt(major[0]) >= 17;
11
- }
7
+ import { captureReactException } from './error.js';
12
8
 
13
9
  const UNKNOWN_COMPONENT = 'unknown';
14
10
 
@@ -18,25 +14,6 @@ const INITIAL_STATE = {
18
14
  eventId: null,
19
15
  };
20
16
 
21
- function setCause(error, cause) {
22
- const seenErrors = new WeakMap();
23
-
24
- function recurse(error, cause) {
25
- // If we've already seen the error, there is a recursive loop somewhere in the error's
26
- // cause chain. Let's just bail out then to prevent a stack overflow.
27
- if (seenErrors.has(error)) {
28
- return;
29
- }
30
- if (error.cause) {
31
- seenErrors.set(error, true);
32
- return recurse(error.cause, cause);
33
- }
34
- error.cause = cause;
35
- }
36
-
37
- recurse(error, cause);
38
- }
39
-
40
17
  /**
41
18
  * A ErrorBoundary component that logs errors to Sentry.
42
19
  * NOTE: If you are a Sentry user, and you are seeing this stack frame, it means the
@@ -61,41 +38,21 @@ class ErrorBoundary extends React.Component {
61
38
  }
62
39
  }
63
40
 
64
- componentDidCatch(error, { componentStack }) {
41
+ componentDidCatch(error, errorInfo) {
42
+ const { componentStack } = errorInfo;
43
+ // TODO(v9): Remove this check and type `componentStack` to be React.ErrorInfo['componentStack'].
44
+ const passedInComponentStack = componentStack == null ? undefined : componentStack;
45
+
65
46
  const { beforeCapture, onError, showDialog, dialogOptions } = this.props;
66
47
  withScope(scope => {
67
- // If on React version >= 17, create stack trace from componentStack param and links
68
- // to to the original error using `error.cause` otherwise relies on error param for stacktrace.
69
- // Linking errors requires the `LinkedErrors` integration be enabled.
70
- // See: https://reactjs.org/blog/2020/08/10/react-v17-rc.html#native-component-stacks
71
- //
72
- // Although `componentDidCatch` is typed to accept an `Error` object, it can also be invoked
73
- // with non-error objects. This is why we need to check if the error is an error-like object.
74
- // See: https://github.com/getsentry/sentry-javascript/issues/6167
75
- if (isAtLeastReact17(React.version) && isError(error)) {
76
- const errorBoundaryError = new Error(error.message);
77
- errorBoundaryError.name = `React ErrorBoundary ${error.name}`;
78
- errorBoundaryError.stack = componentStack;
79
-
80
- // Using the `LinkedErrors` integration to link the errors together.
81
- setCause(error, errorBoundaryError);
82
- }
83
-
84
48
  if (beforeCapture) {
85
- beforeCapture(scope, error, componentStack);
49
+ beforeCapture(scope, error, passedInComponentStack);
86
50
  }
87
51
 
88
- const eventId = captureException(error, {
89
- captureContext: {
90
- contexts: { react: { componentStack } },
91
- },
92
- // If users provide a fallback component we can assume they are handling the error.
93
- // Therefore, we set the mechanism depending on the presence of the fallback prop.
94
- mechanism: { handled: !!this.props.fallback },
95
- });
52
+ const eventId = captureReactException(error, errorInfo, { mechanism: { handled: !!this.props.fallback } });
96
53
 
97
54
  if (onError) {
98
- onError(error, componentStack, eventId);
55
+ onError(error, passedInComponentStack, eventId);
99
56
  }
100
57
  if (showDialog) {
101
58
  this._lastEventId = eventId;
@@ -175,7 +132,6 @@ function withErrorBoundary(
175
132
  WrappedComponent,
176
133
  errorBoundaryOptions,
177
134
  ) {
178
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
179
135
  const componentDisplayName = WrappedComponent.displayName || WrappedComponent.name || UNKNOWN_COMPONENT;
180
136
 
181
137
  const Wrapped = (props) => (
@@ -184,7 +140,6 @@ function withErrorBoundary(
184
140
  })
185
141
  );
186
142
 
187
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
188
143
  Wrapped.displayName = `errorBoundary(${componentDisplayName})`;
189
144
 
190
145
  // Copy over static methods from Wrapped component to Profiler HOC
@@ -193,5 +148,5 @@ function withErrorBoundary(
193
148
  return Wrapped;
194
149
  }
195
150
 
196
- export { ErrorBoundary, UNKNOWN_COMPONENT, isAtLeastReact17, withErrorBoundary };
151
+ export { ErrorBoundary, UNKNOWN_COMPONENT, withErrorBoundary };
197
152
  //# sourceMappingURL=errorboundary.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errorboundary.js","sources":["../../src/errorboundary.tsx"],"sourcesContent":["import type { ReportDialogOptions } from '@sentry/browser';\nimport { captureException, getClient, showReportDialog, withScope } from '@sentry/browser';\nimport type { Scope } from '@sentry/types';\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: unknown;\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: unknown, 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: unknown, componentStack: string | null, eventId: string | null) => void) | undefined;\n /** Called on componentWillUnmount() */\n onUnmount?: ((error: unknown, 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: unknown, componentStack: string | undefined) => 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: unknown;\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.\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 && props.showDialog) {\n this._openFallbackReportDialog = false;\n client.on('afterSendEvent', event => {\n if (!event.type && this._lastEventId && event.event_id === this._lastEventId) {\n showReportDialog({ ...props.dialogOptions, eventId: this._lastEventId });\n }\n });\n }\n }\n\n public componentDidCatch(error: unknown, { 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 // If users provide a fallback component we can assume they are handling the error.\n // Therefore, we set the mechanism depending on the presence of the fallback prop.\n mechanism: { handled: !!this.props.fallback },\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 = React.createElement(fallback, {\n error: state.error,\n componentStack: state.componentStack as string,\n resetError: this.resetErrorBoundary,\n eventId: state.eventId as string,\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":["_jsx"],"mappings":";;;;;;;AASO,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;;AAmD1C,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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AA,CAAA,WAAA,GAAA,CAAA,cAAA,EAAA,oBAAA,CAAA,CAAA,CAAA,CAAA;AACA;AACA;AACA;AACA,EAAA,oBAAA,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 } from '@sentry/browser';\nimport { getClient, showReportDialog, withScope } from '@sentry/browser';\nimport type { Scope } from '@sentry/types';\nimport { logger } from '@sentry/utils';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nimport { DEBUG_BUILD } from './debug-build';\nimport { captureReactException } from './error';\n\nexport const UNKNOWN_COMPONENT = 'unknown';\n\nexport type FallbackRender = (errorData: {\n error: unknown;\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: unknown, componentStack: string | undefined, 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: unknown, componentStack: string | null | undefined, eventId: string | null) => void) | undefined;\n /** Called on componentWillUnmount() */\n onUnmount?: ((error: unknown, componentStack: string | null | undefined, 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: unknown, componentStack: string | undefined) => 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: unknown;\n eventId: string;\n };\n\nconst INITIAL_STATE = {\n componentStack: null,\n error: null,\n eventId: null,\n};\n\n/**\n * A ErrorBoundary component that logs errors to Sentry.\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 && props.showDialog) {\n this._openFallbackReportDialog = false;\n client.on('afterSendEvent', event => {\n if (!event.type && this._lastEventId && event.event_id === this._lastEventId) {\n showReportDialog({ ...props.dialogOptions, eventId: this._lastEventId });\n }\n });\n }\n }\n\n public componentDidCatch(error: unknown, errorInfo: React.ErrorInfo): void {\n const { componentStack } = errorInfo;\n // TODO(v9): Remove this check and type `componentStack` to be React.ErrorInfo['componentStack'].\n const passedInComponentStack: string | undefined = componentStack == null ? undefined : componentStack;\n\n const { beforeCapture, onError, showDialog, dialogOptions } = this.props;\n withScope(scope => {\n if (beforeCapture) {\n beforeCapture(scope, error, passedInComponentStack);\n }\n\n const eventId = captureReactException(error, errorInfo, { mechanism: { handled: !!this.props.fallback } });\n\n if (onError) {\n onError(error, passedInComponentStack, 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 = React.createElement(fallback, {\n error: state.error,\n componentStack: state.componentStack as string,\n resetError: this.resetErrorBoundary,\n eventId: state.eventId as string,\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 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 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":["_jsx"],"mappings":";;;;;;;;AAUO,MAAM,iBAAkB,GAAE,UAAS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,QAAQ,eAAe,MAAM,CAAC,IAAI,CAAC,+CAA+C,CAAC,CAAA;AACnF,OAAM;AACN;AACA;AACA,MAAM,OAAO,IAAI,CAAA;AACjB,KAAI;AACJ;AACA,IAAI,IAAI,OAAO,QAAS,KAAI,UAAU,EAAE;AACxC,MAAM,OAAO,CAAC,QAAS,IAA2B,CAAA;AAClD,KAAI;AACJ,IAAI,OAAO,QAAQ,CAAA;AACnB,GAAE;AACF,CAAA;AACA;AACA;AACA,SAAS,iBAAiB;AAC1B,EAAE,gBAAgB;AAClB,EAAE,oBAAoB;AACtB,EAAe;AACf,EAAE,MAAM,oBAAqB,GAAE,gBAAgB,CAAC,WAAY,IAAG,gBAAgB,CAAC,IAAK,IAAG,iBAAiB,CAAA;AACzG;AACA,EAAE,MAAM,OAAO,GAAgB,CAAC,KAAK;AACrC,IAAIA,GAAC,CAAA,aAAA,EAAA,EAAc,GAAI,oBAAoB,EAAE,QAAA;AAC7C,MAAMA,GAAC,CAAA,gBAAA,EAAA,EAAiB,GAAI,KAAK,IAAI;AACrC,KAAI,CAAA;AACJ,GAAG,CAAA;AACH;AACA,EAAE,OAAO,CAAC,WAAA,GAAc,CAAC,cAAc,EAAE,oBAAoB,CAAC,CAAC,CAAC,CAAA;AAChE;AACA;AACA;AACA,EAAE,oBAAoB,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAA;AACjD,EAAE,OAAO,OAAO,CAAA;AAChB;;;;"}
package/esm/index.js CHANGED
@@ -1,9 +1,11 @@
1
1
  export * from '@sentry/browser';
2
2
  export { init } from './sdk.js';
3
+ export { reactErrorHandler } from './error.js';
3
4
  export { Profiler, useProfiler, withProfiler } from './profiler.js';
4
5
  export { ErrorBoundary, withErrorBoundary } from './errorboundary.js';
5
6
  export { createReduxEnhancer } from './redux.js';
6
7
  export { reactRouterV3BrowserTracingIntegration } from './reactrouterv3.js';
8
+ export { tanstackRouterBrowserTracingIntegration } from './tanstackrouter.js';
7
9
  export { reactRouterV4BrowserTracingIntegration, reactRouterV5BrowserTracingIntegration, withSentryRouting } from './reactrouter.js';
8
10
  export { reactRouterV6BrowserTracingIntegration, withSentryReactRouterV6Routing, wrapCreateBrowserRouter, wrapUseRoutes } from './reactrouterv6.js';
9
11
  //# sourceMappingURL=index.js.map
package/esm/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
@@ -13,7 +13,7 @@ let _createRoutesFromChildren;
13
13
  let _matchRoutes;
14
14
  let _stripBasename = false;
15
15
 
16
- const CLIENTS_WITH_INSTRUMENT_NAVIGATION = [];
16
+ const CLIENTS_WITH_INSTRUMENT_NAVIGATION = new WeakSet();
17
17
 
18
18
  /**
19
19
  * A browser tracing integration that uses React Router v6 to instrument navigations.
@@ -65,7 +65,7 @@ function reactRouterV6BrowserTracingIntegration(
65
65
  }
66
66
 
67
67
  if (instrumentNavigation) {
68
- CLIENTS_WITH_INSTRUMENT_NAVIGATION.push(client);
68
+ CLIENTS_WITH_INSTRUMENT_NAVIGATION.add(client);
69
69
  }
70
70
  },
71
71
  };
@@ -179,7 +179,7 @@ function handleNavigation(
179
179
  const branches = Array.isArray(matches) ? matches : _matchRoutes(routes, location, basename);
180
180
 
181
181
  const client = getClient();
182
- if (!client || !CLIENTS_WITH_INSTRUMENT_NAVIGATION.includes(client)) {
182
+ if (!client || !CLIENTS_WITH_INSTRUMENT_NAVIGATION.has(client)) {
183
183
  return;
184
184
  }
185
185
 
@@ -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 {\n WINDOW,\n browserTracingIntegration,\n startBrowserTracingNavigationSpan,\n startBrowserTracingPageLoadSpan,\n} from '@sentry/browser';\nimport {\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n getActiveSpan,\n getClient,\n getCurrentScope,\n getRootSpan,\n spanToJSON,\n} from '@sentry/core';\nimport type { Client, Integration, Span, 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 _useEffect: UseEffect;\nlet _useLocation: UseLocation;\nlet _useNavigationType: UseNavigationType;\nlet _createRoutesFromChildren: CreateRoutesFromChildren;\nlet _matchRoutes: MatchRoutes;\nlet _stripBasename: boolean = false;\n\nconst CLIENTS_WITH_INSTRUMENT_NAVIGATION: Client[] = [];\n\ninterface ReactRouterOptions {\n useEffect: UseEffect;\n useLocation: UseLocation;\n useNavigationType: UseNavigationType;\n createRoutesFromChildren: CreateRoutesFromChildren;\n matchRoutes: MatchRoutes;\n stripBasename?: boolean;\n}\n\n/**\n * A browser tracing integration that uses React Router v6 to instrument navigations.\n * Expects `useEffect`, `useLocation`, `useNavigationType`, `createRoutesFromChildren` and `matchRoutes` to be passed as options.\n */\nexport function reactRouterV6BrowserTracingIntegration(\n options: Parameters<typeof browserTracingIntegration>[0] & ReactRouterOptions,\n): Integration {\n const integration = browserTracingIntegration({\n ...options,\n instrumentPageLoad: false,\n instrumentNavigation: false,\n });\n\n const {\n useEffect,\n useLocation,\n useNavigationType,\n createRoutesFromChildren,\n matchRoutes,\n stripBasename,\n instrumentPageLoad = true,\n instrumentNavigation = true,\n } = options;\n\n return {\n ...integration,\n setup() {\n _useEffect = useEffect;\n _useLocation = useLocation;\n _useNavigationType = useNavigationType;\n _matchRoutes = matchRoutes;\n _createRoutesFromChildren = createRoutesFromChildren;\n _stripBasename = stripBasename || false;\n },\n afterAllSetup(client) {\n integration.afterAllSetup(client);\n\n const initPathName = WINDOW && WINDOW.location && WINDOW.location.pathname;\n if (instrumentPageLoad && initPathName) {\n startBrowserTracingPageLoadSpan(client, {\n name: initPathName,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'pageload',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.pageload.react.reactrouter_v6',\n },\n });\n }\n\n if (instrumentNavigation) {\n CLIENTS_WITH_INSTRUMENT_NAVIGATION.push(client);\n }\n },\n };\n}\n\n/**\n * Strip the basename from a pathname if exists.\n *\n * Vendored and modified from `react-router`\n * https://github.com/remix-run/react-router/blob/462bb712156a3f739d6139a0f14810b76b002df6/packages/router/utils.ts#L1038\n */\nfunction stripBasenameFromPathname(pathname: string, basename: string): string {\n if (!basename || basename === '/') {\n return pathname;\n }\n\n if (!pathname.toLowerCase().startsWith(basename.toLowerCase())) {\n return pathname;\n }\n\n // We want to leave trailing slash behavior in the user's control, so if they\n // specify a basename with a trailing slash, we should support it\n const startIndex = basename.endsWith('/') ? basename.length - 1 : basename.length;\n const nextChar = pathname.charAt(startIndex);\n if (nextChar && nextChar !== '/') {\n // pathname does not start with basename/\n return pathname;\n }\n\n return pathname.slice(startIndex) || '/';\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 [_stripBasename ? stripBasenameFromPathname(location.pathname, basename) : 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 [_stripBasename ? stripBasenameFromPathname(branch.pathname, basename) : 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 [(_stripBasename ? '' : basename) + newPath, 'route'];\n }\n return [(_stripBasename ? '' : basename) + pathBuilder, 'route'];\n }\n }\n }\n }\n }\n\n return [_stripBasename ? stripBasenameFromPathname(location.pathname, basename) : location.pathname, 'url'];\n}\n\nfunction updatePageloadTransaction(\n activeRootSpan: Span | undefined,\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 (branches) {\n const [name, source] = getNormalizedName(routes, location, branches, basename);\n\n getCurrentScope().setTransactionName(name);\n\n if (activeRootSpan) {\n activeRootSpan.updateName(name);\n activeRootSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, source);\n }\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 const client = getClient();\n if (!client || !CLIENTS_WITH_INSTRUMENT_NAVIGATION.includes(client)) {\n return;\n }\n\n if ((navigationType === 'PUSH' || navigationType === 'POP') && branches) {\n const [name, source] = getNormalizedName(routes, location, branches, basename);\n\n startBrowserTracingNavigationSpan(client, {\n name,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.react.reactrouter_v6',\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 (!_useEffect || !_useLocation || !_useNavigationType || !_createRoutesFromChildren || !_matchRoutes) {\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}.`);\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(getActiveRootSpan(), 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) {\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(getActiveRootSpan(), 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 if (!_useEffect || !_useLocation || !_useNavigationType || !_matchRoutes) {\n DEBUG_BUILD &&\n logger.warn(\n 'reactRouterV6Instrumentation was unable to wrap the `createRouter` function because of one or more missing parameters.',\n );\n\n return createRouterFunction;\n }\n\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 const activeRootSpan = getActiveRootSpan();\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' && activeRootSpan) {\n updatePageloadTransaction(activeRootSpan, router.state.location, routes, undefined, basename);\n }\n\n router.subscribe((state: RouterState) => {\n const location = state.location;\n if (state.historyAction === 'PUSH' || state.historyAction === 'POP') {\n handleNavigation(location, routes, state.historyAction, undefined, basename);\n }\n });\n\n return router;\n };\n}\n\nfunction getActiveRootSpan(): Span | undefined {\n const span = getActiveSpan();\n const rootSpan = span ? getRootSpan(span) : undefined;\n\n if (!rootSpan) {\n return undefined;\n }\n\n const op = spanToJSON(rootSpan).op;\n\n // Only use this root span if it is a pageload or navigation span\n return op === 'navigation' || op === 'pageload' ? rootSpan : undefined;\n}\n"],"names":["_jsx"],"mappings":";;;;;;;;AA0CA,IAAI,UAAU,CAAA;AACd,IAAI,YAAY,CAAA;AAChB,IAAI,kBAAkB,CAAA;AACtB,IAAI,yBAAyB,CAAA;AAC7B,IAAI,YAAY,CAAA;AAChB,IAAI,cAAc,GAAY,KAAK,CAAA;AACnC;AACA,MAAM,kCAAkC,GAAa,EAAE,CAAA;;AAWvD;AACA;AACA;AACA;AACO,SAAS,sCAAsC;AACtD,EAAE,OAAO;AACT,EAAe;AACf,EAAE,MAAM,WAAA,GAAc,yBAAyB,CAAC;AAChD,IAAI,GAAG,OAAO;AACd,IAAI,kBAAkB,EAAE,KAAK;AAC7B,IAAI,oBAAoB,EAAE,KAAK;AAC/B,GAAG,CAAC,CAAA;AACJ;AACA,EAAE,MAAM;AACR,IAAI,SAAS;AACb,IAAI,WAAW;AACf,IAAI,iBAAiB;AACrB,IAAI,wBAAwB;AAC5B,IAAI,WAAW;AACf,IAAI,aAAa;AACjB,IAAI,kBAAA,GAAqB,IAAI;AAC7B,IAAI,oBAAA,GAAuB,IAAI;AAC/B,GAAE,GAAI,OAAO,CAAA;AACb;AACA,EAAE,OAAO;AAC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,MAAA,QAAA,GAAA,KAAA,CAAA,QAAA,CAAA;AACA,MAAA,IAAA,KAAA,CAAA,aAAA,KAAA,MAAA,IAAA,KAAA,CAAA,aAAA,KAAA,KAAA,EAAA;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,CAAA;AACA;AACA,SAAA,iBAAA,GAAA;AACA,EAAA,MAAA,IAAA,GAAA,aAAA,EAAA,CAAA;AACA,EAAA,MAAA,QAAA,GAAA,IAAA,GAAA,WAAA,CAAA,IAAA,CAAA,GAAA,SAAA,CAAA;AACA;AACA,EAAA,IAAA,CAAA,QAAA,EAAA;AACA,IAAA,OAAA,SAAA,CAAA;AACA,GAAA;AACA;AACA,EAAA,MAAA,EAAA,GAAA,UAAA,CAAA,QAAA,CAAA,CAAA,EAAA,CAAA;AACA;AACA;AACA,EAAA,OAAA,EAAA,KAAA,YAAA,IAAA,EAAA,KAAA,UAAA,GAAA,QAAA,GAAA,SAAA,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 {\n WINDOW,\n browserTracingIntegration,\n startBrowserTracingNavigationSpan,\n startBrowserTracingPageLoadSpan,\n} from '@sentry/browser';\nimport {\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n getActiveSpan,\n getClient,\n getCurrentScope,\n getRootSpan,\n spanToJSON,\n} from '@sentry/core';\nimport type { Client, Integration, Span, 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 _useEffect: UseEffect;\nlet _useLocation: UseLocation;\nlet _useNavigationType: UseNavigationType;\nlet _createRoutesFromChildren: CreateRoutesFromChildren;\nlet _matchRoutes: MatchRoutes;\nlet _stripBasename: boolean = false;\n\nconst CLIENTS_WITH_INSTRUMENT_NAVIGATION = new WeakSet<Client>();\n\ninterface ReactRouterOptions {\n useEffect: UseEffect;\n useLocation: UseLocation;\n useNavigationType: UseNavigationType;\n createRoutesFromChildren: CreateRoutesFromChildren;\n matchRoutes: MatchRoutes;\n stripBasename?: boolean;\n}\n\n/**\n * A browser tracing integration that uses React Router v6 to instrument navigations.\n * Expects `useEffect`, `useLocation`, `useNavigationType`, `createRoutesFromChildren` and `matchRoutes` to be passed as options.\n */\nexport function reactRouterV6BrowserTracingIntegration(\n options: Parameters<typeof browserTracingIntegration>[0] & ReactRouterOptions,\n): Integration {\n const integration = browserTracingIntegration({\n ...options,\n instrumentPageLoad: false,\n instrumentNavigation: false,\n });\n\n const {\n useEffect,\n useLocation,\n useNavigationType,\n createRoutesFromChildren,\n matchRoutes,\n stripBasename,\n instrumentPageLoad = true,\n instrumentNavigation = true,\n } = options;\n\n return {\n ...integration,\n setup() {\n _useEffect = useEffect;\n _useLocation = useLocation;\n _useNavigationType = useNavigationType;\n _matchRoutes = matchRoutes;\n _createRoutesFromChildren = createRoutesFromChildren;\n _stripBasename = stripBasename || false;\n },\n afterAllSetup(client) {\n integration.afterAllSetup(client);\n\n const initPathName = WINDOW && WINDOW.location && WINDOW.location.pathname;\n if (instrumentPageLoad && initPathName) {\n startBrowserTracingPageLoadSpan(client, {\n name: initPathName,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'pageload',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.pageload.react.reactrouter_v6',\n },\n });\n }\n\n if (instrumentNavigation) {\n CLIENTS_WITH_INSTRUMENT_NAVIGATION.add(client);\n }\n },\n };\n}\n\n/**\n * Strip the basename from a pathname if exists.\n *\n * Vendored and modified from `react-router`\n * https://github.com/remix-run/react-router/blob/462bb712156a3f739d6139a0f14810b76b002df6/packages/router/utils.ts#L1038\n */\nfunction stripBasenameFromPathname(pathname: string, basename: string): string {\n if (!basename || basename === '/') {\n return pathname;\n }\n\n if (!pathname.toLowerCase().startsWith(basename.toLowerCase())) {\n return pathname;\n }\n\n // We want to leave trailing slash behavior in the user's control, so if they\n // specify a basename with a trailing slash, we should support it\n const startIndex = basename.endsWith('/') ? basename.length - 1 : basename.length;\n const nextChar = pathname.charAt(startIndex);\n if (nextChar && nextChar !== '/') {\n // pathname does not start with basename/\n return pathname;\n }\n\n return pathname.slice(startIndex) || '/';\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 [_stripBasename ? stripBasenameFromPathname(location.pathname, basename) : 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 [_stripBasename ? stripBasenameFromPathname(branch.pathname, basename) : 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 [(_stripBasename ? '' : basename) + newPath, 'route'];\n }\n return [(_stripBasename ? '' : basename) + pathBuilder, 'route'];\n }\n }\n }\n }\n }\n\n return [_stripBasename ? stripBasenameFromPathname(location.pathname, basename) : location.pathname, 'url'];\n}\n\nfunction updatePageloadTransaction(\n activeRootSpan: Span | undefined,\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 (branches) {\n const [name, source] = getNormalizedName(routes, location, branches, basename);\n\n getCurrentScope().setTransactionName(name);\n\n if (activeRootSpan) {\n activeRootSpan.updateName(name);\n activeRootSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, source);\n }\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 const client = getClient();\n if (!client || !CLIENTS_WITH_INSTRUMENT_NAVIGATION.has(client)) {\n return;\n }\n\n if ((navigationType === 'PUSH' || navigationType === 'POP') && branches) {\n const [name, source] = getNormalizedName(routes, location, branches, basename);\n\n startBrowserTracingNavigationSpan(client, {\n name,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.react.reactrouter_v6',\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 (!_useEffect || !_useLocation || !_useNavigationType || !_createRoutesFromChildren || !_matchRoutes) {\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}.`);\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(getActiveRootSpan(), 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) {\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(getActiveRootSpan(), 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 if (!_useEffect || !_useLocation || !_useNavigationType || !_matchRoutes) {\n DEBUG_BUILD &&\n logger.warn(\n 'reactRouterV6Instrumentation was unable to wrap the `createRouter` function because of one or more missing parameters.',\n );\n\n return createRouterFunction;\n }\n\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 const activeRootSpan = getActiveRootSpan();\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' && activeRootSpan) {\n updatePageloadTransaction(activeRootSpan, router.state.location, routes, undefined, basename);\n }\n\n router.subscribe((state: RouterState) => {\n const location = state.location;\n if (state.historyAction === 'PUSH' || state.historyAction === 'POP') {\n handleNavigation(location, routes, state.historyAction, undefined, basename);\n }\n });\n\n return router;\n };\n}\n\nfunction getActiveRootSpan(): Span | undefined {\n const span = getActiveSpan();\n const rootSpan = span ? getRootSpan(span) : undefined;\n\n if (!rootSpan) {\n return undefined;\n }\n\n const op = spanToJSON(rootSpan).op;\n\n // Only use this root span if it is a pageload or navigation span\n return op === 'navigation' || op === 'pageload' ? rootSpan : undefined;\n}\n"],"names":["_jsx"],"mappings":";;;;;;;;AA0CA,IAAI,UAAU,CAAA;AACd,IAAI,YAAY,CAAA;AAChB,IAAI,kBAAkB,CAAA;AACtB,IAAI,yBAAyB,CAAA;AAC7B,IAAI,YAAY,CAAA;AAChB,IAAI,cAAc,GAAY,KAAK,CAAA;AACnC;AACA,MAAM,kCAAmC,GAAE,IAAI,OAAO,EAAU,CAAA;;AAWhE;AACA;AACA;AACA;AACO,SAAS,sCAAsC;AACtD,EAAE,OAAO;AACT,EAAe;AACf,EAAE,MAAM,WAAA,GAAc,yBAAyB,CAAC;AAChD,IAAI,GAAG,OAAO;AACd,IAAI,kBAAkB,EAAE,KAAK;AAC7B,IAAI,oBAAoB,EAAE,KAAK;AAC/B,GAAG,CAAC,CAAA;AACJ;AACA,EAAE,MAAM;AACR,IAAI,SAAS;AACb,IAAI,WAAW;AACf,IAAI,iBAAiB;AACrB,IAAI,wBAAwB;AAC5B,IAAI,WAAW;AACf,IAAI,aAAa;AACjB,IAAI,kBAAA,GAAqB,IAAI;AAC7B,IAAI,oBAAA,GAAuB,IAAI;AAC/B,GAAE,GAAI,OAAO,CAAA;AACb;AACA,EAAE,OAAO;AACT,IAAI,GAAG,WAAW;AAClB,IAAI,KAAK,GAAG;AACZ,MAAM,UAAA,GAAa,SAAS,CAAA;AAC5B,MAAM,YAAA,GAAe,WAAW,CAAA;AAChC,MAAM,kBAAA,GAAqB,iBAAiB,CAAA;AAC5C,MAAM,YAAA,GAAe,WAAW,CAAA;AAChC,MAAM,yBAAA,GAA4B,wBAAwB,C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