@sentry/react 10.29.0 → 10.30.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/build/cjs/reactrouter-compat-utils/instrumentation.js +45 -34
- package/build/cjs/reactrouter-compat-utils/instrumentation.js.map +1 -1
- package/build/cjs/reactrouter-compat-utils/lazy-routes.js +77 -6
- package/build/cjs/reactrouter-compat-utils/lazy-routes.js.map +1 -1
- package/build/cjs/reactrouter-compat-utils/utils.js +64 -0
- package/build/cjs/reactrouter-compat-utils/utils.js.map +1 -1
- package/build/cjs/reactrouterv6.js +1 -0
- package/build/cjs/reactrouterv6.js.map +1 -1
- package/build/cjs/reactrouterv7.js +1 -0
- package/build/cjs/reactrouterv7.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/reactrouter-compat-utils/instrumentation.js +38 -27
- package/build/esm/reactrouter-compat-utils/instrumentation.js.map +1 -1
- package/build/esm/reactrouter-compat-utils/lazy-routes.js +78 -7
- package/build/esm/reactrouter-compat-utils/lazy-routes.js.map +1 -1
- package/build/esm/reactrouter-compat-utils/utils.js +61 -1
- package/build/esm/reactrouter-compat-utils/utils.js.map +1 -1
- package/build/esm/reactrouterv6.js +1 -0
- package/build/esm/reactrouterv6.js.map +1 -1
- package/build/esm/reactrouterv7.js +1 -0
- package/build/esm/reactrouterv7.js.map +1 -1
- package/build/types/reactrouter-compat-utils/index.d.ts +1 -1
- package/build/types/reactrouter-compat-utils/index.d.ts.map +1 -1
- package/build/types/reactrouter-compat-utils/instrumentation.d.ts +3 -1
- package/build/types/reactrouter-compat-utils/instrumentation.d.ts.map +1 -1
- package/build/types/reactrouter-compat-utils/lazy-routes.d.ts +7 -3
- package/build/types/reactrouter-compat-utils/lazy-routes.d.ts.map +1 -1
- package/build/types/reactrouter-compat-utils/utils.d.ts +24 -1
- package/build/types/reactrouter-compat-utils/utils.d.ts.map +1 -1
- package/build/types-ts3.8/reactrouter-compat-utils/index.d.ts +1 -1
- package/build/types-ts3.8/reactrouter-compat-utils/instrumentation.d.ts +3 -1
- package/build/types-ts3.8/reactrouter-compat-utils/lazy-routes.d.ts +7 -3
- package/build/types-ts3.8/reactrouter-compat-utils/utils.d.ts +24 -1
- package/package.json +3 -3
|
@@ -1,21 +1,85 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
|
+
const browser = require('@sentry/browser');
|
|
3
4
|
const core = require('@sentry/core');
|
|
4
5
|
const debugBuild = require('../debug-build.js');
|
|
6
|
+
const utils = require('./utils.js');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Captures location at invocation time. Prefers navigation context over window.location
|
|
10
|
+
* since window.location hasn't updated yet when async handlers are invoked.
|
|
11
|
+
*/
|
|
12
|
+
function captureCurrentLocation() {
|
|
13
|
+
const navContext = utils.getNavigationContext();
|
|
14
|
+
// Only use navigation context if targetPath is defined (it can be undefined
|
|
15
|
+
// if patchRoutesOnNavigation was invoked without a path argument)
|
|
16
|
+
if (navContext?.targetPath) {
|
|
17
|
+
return {
|
|
18
|
+
pathname: navContext.targetPath,
|
|
19
|
+
search: '',
|
|
20
|
+
hash: '',
|
|
21
|
+
state: null,
|
|
22
|
+
key: 'default',
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (typeof browser.WINDOW !== 'undefined') {
|
|
27
|
+
try {
|
|
28
|
+
const windowLocation = browser.WINDOW.location;
|
|
29
|
+
if (windowLocation) {
|
|
30
|
+
return {
|
|
31
|
+
pathname: windowLocation.pathname,
|
|
32
|
+
search: windowLocation.search || '',
|
|
33
|
+
hash: windowLocation.hash || '',
|
|
34
|
+
state: null,
|
|
35
|
+
key: 'default',
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
} catch {
|
|
39
|
+
debugBuild.DEBUG_BUILD && core.debug.warn('[React Router] Could not access window.location');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Captures the active span at invocation time. Prefers navigation context span
|
|
47
|
+
* to ensure we update the correct span even if another navigation starts.
|
|
48
|
+
*/
|
|
49
|
+
function captureActiveSpan() {
|
|
50
|
+
const navContext = utils.getNavigationContext();
|
|
51
|
+
if (navContext) {
|
|
52
|
+
return navContext.span;
|
|
53
|
+
}
|
|
54
|
+
return utils.getActiveRootSpan();
|
|
55
|
+
}
|
|
5
56
|
|
|
6
57
|
/**
|
|
7
58
|
* Creates a proxy wrapper for an async handler function.
|
|
59
|
+
* Captures both the location and the active span at invocation time to ensure
|
|
60
|
+
* the correct span is updated when the handler resolves.
|
|
8
61
|
*/
|
|
9
62
|
function createAsyncHandlerProxy(
|
|
10
63
|
originalFunction,
|
|
11
64
|
route,
|
|
12
65
|
handlerKey,
|
|
13
|
-
processResolvedRoutes
|
|
66
|
+
processResolvedRoutes
|
|
67
|
+
|
|
68
|
+
,
|
|
14
69
|
) {
|
|
15
70
|
const proxy = new Proxy(originalFunction, {
|
|
16
71
|
apply(target, thisArg, argArray) {
|
|
72
|
+
const locationAtInvocation = captureCurrentLocation();
|
|
73
|
+
const spanAtInvocation = captureActiveSpan();
|
|
17
74
|
const result = target.apply(thisArg, argArray);
|
|
18
|
-
handleAsyncHandlerResult(
|
|
75
|
+
handleAsyncHandlerResult(
|
|
76
|
+
result,
|
|
77
|
+
route,
|
|
78
|
+
handlerKey,
|
|
79
|
+
processResolvedRoutes,
|
|
80
|
+
locationAtInvocation,
|
|
81
|
+
spanAtInvocation,
|
|
82
|
+
);
|
|
19
83
|
return result;
|
|
20
84
|
},
|
|
21
85
|
});
|
|
@@ -27,25 +91,30 @@ function createAsyncHandlerProxy(
|
|
|
27
91
|
|
|
28
92
|
/**
|
|
29
93
|
* Handles the result of an async handler function call.
|
|
94
|
+
* Passes the captured span through to ensure the correct span is updated.
|
|
30
95
|
*/
|
|
31
96
|
function handleAsyncHandlerResult(
|
|
32
97
|
result,
|
|
33
98
|
route,
|
|
34
99
|
handlerKey,
|
|
35
|
-
processResolvedRoutes
|
|
100
|
+
processResolvedRoutes
|
|
101
|
+
|
|
102
|
+
,
|
|
103
|
+
currentLocation,
|
|
104
|
+
capturedSpan,
|
|
36
105
|
) {
|
|
37
106
|
if (core.isThenable(result)) {
|
|
38
107
|
(result )
|
|
39
108
|
.then((resolvedRoutes) => {
|
|
40
109
|
if (Array.isArray(resolvedRoutes)) {
|
|
41
|
-
processResolvedRoutes(resolvedRoutes, route);
|
|
110
|
+
processResolvedRoutes(resolvedRoutes, route, currentLocation ?? undefined, capturedSpan);
|
|
42
111
|
}
|
|
43
112
|
})
|
|
44
113
|
.catch((e) => {
|
|
45
114
|
debugBuild.DEBUG_BUILD && core.debug.warn(`Error resolving async handler '${handlerKey}' for route`, route, e);
|
|
46
115
|
});
|
|
47
116
|
} else if (Array.isArray(result)) {
|
|
48
|
-
processResolvedRoutes(result, route);
|
|
117
|
+
processResolvedRoutes(result, route, currentLocation ?? undefined, capturedSpan);
|
|
49
118
|
}
|
|
50
119
|
}
|
|
51
120
|
|
|
@@ -54,7 +123,9 @@ function handleAsyncHandlerResult(
|
|
|
54
123
|
*/
|
|
55
124
|
function checkRouteForAsyncHandler(
|
|
56
125
|
route,
|
|
57
|
-
processResolvedRoutes
|
|
126
|
+
processResolvedRoutes
|
|
127
|
+
|
|
128
|
+
,
|
|
58
129
|
) {
|
|
59
130
|
// Set up proxies for any functions in the route's handle
|
|
60
131
|
if (route.handle && typeof route.handle === 'object') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazy-routes.js","sources":["../../../src/reactrouter-compat-utils/lazy-routes.tsx"],"sourcesContent":["import { addNonEnumerableProperty, debug, isThenable } from '@sentry/core';\nimport { DEBUG_BUILD } from '../debug-build';\nimport type { Location, RouteObject } from '../types';\n\n/**\n * Creates a proxy wrapper for an async handler function.\n */\nexport function createAsyncHandlerProxy(\n originalFunction: (...args: unknown[]) => unknown,\n route: RouteObject,\n handlerKey: string,\n processResolvedRoutes: (resolvedRoutes: RouteObject[]
|
|
1
|
+
{"version":3,"file":"lazy-routes.js","sources":["../../../src/reactrouter-compat-utils/lazy-routes.tsx"],"sourcesContent":["import { WINDOW } from '@sentry/browser';\nimport type { Span } from '@sentry/core';\nimport { addNonEnumerableProperty, debug, isThenable } from '@sentry/core';\nimport { DEBUG_BUILD } from '../debug-build';\nimport type { Location, RouteObject } from '../types';\nimport { getActiveRootSpan, getNavigationContext } from './utils';\n\n/**\n * Captures location at invocation time. Prefers navigation context over window.location\n * since window.location hasn't updated yet when async handlers are invoked.\n */\nfunction captureCurrentLocation(): Location | null {\n const navContext = getNavigationContext();\n // Only use navigation context if targetPath is defined (it can be undefined\n // if patchRoutesOnNavigation was invoked without a path argument)\n if (navContext?.targetPath) {\n return {\n pathname: navContext.targetPath,\n search: '',\n hash: '',\n state: null,\n key: 'default',\n };\n }\n\n if (typeof WINDOW !== 'undefined') {\n try {\n const windowLocation = WINDOW.location;\n if (windowLocation) {\n return {\n pathname: windowLocation.pathname,\n search: windowLocation.search || '',\n hash: windowLocation.hash || '',\n state: null,\n key: 'default',\n };\n }\n } catch {\n DEBUG_BUILD && debug.warn('[React Router] Could not access window.location');\n }\n }\n return null;\n}\n\n/**\n * Captures the active span at invocation time. Prefers navigation context span\n * to ensure we update the correct span even if another navigation starts.\n */\nfunction captureActiveSpan(): Span | undefined {\n const navContext = getNavigationContext();\n if (navContext) {\n return navContext.span;\n }\n return getActiveRootSpan();\n}\n\n/**\n * Creates a proxy wrapper for an async handler function.\n * Captures both the location and the active span at invocation time to ensure\n * the correct span is updated when the handler resolves.\n */\nexport function createAsyncHandlerProxy(\n originalFunction: (...args: unknown[]) => unknown,\n route: RouteObject,\n handlerKey: string,\n processResolvedRoutes: (\n resolvedRoutes: RouteObject[],\n parentRoute?: RouteObject,\n currentLocation?: Location,\n capturedSpan?: Span,\n ) => void,\n): (...args: unknown[]) => unknown {\n const proxy = new Proxy(originalFunction, {\n apply(target: (...args: unknown[]) => unknown, thisArg, argArray) {\n const locationAtInvocation = captureCurrentLocation();\n const spanAtInvocation = captureActiveSpan();\n const result = target.apply(thisArg, argArray);\n handleAsyncHandlerResult(\n result,\n route,\n handlerKey,\n processResolvedRoutes,\n locationAtInvocation,\n spanAtInvocation,\n );\n return result;\n },\n });\n\n addNonEnumerableProperty(proxy, '__sentry_proxied__', true);\n\n return proxy;\n}\n\n/**\n * Handles the result of an async handler function call.\n * Passes the captured span through to ensure the correct span is updated.\n */\nexport function handleAsyncHandlerResult(\n result: unknown,\n route: RouteObject,\n handlerKey: string,\n processResolvedRoutes: (\n resolvedRoutes: RouteObject[],\n parentRoute?: RouteObject,\n currentLocation?: Location,\n capturedSpan?: Span,\n ) => void,\n currentLocation: Location | null,\n capturedSpan: Span | undefined,\n): void {\n if (isThenable(result)) {\n (result as Promise<unknown>)\n .then((resolvedRoutes: unknown) => {\n if (Array.isArray(resolvedRoutes)) {\n processResolvedRoutes(resolvedRoutes, route, currentLocation ?? undefined, capturedSpan);\n }\n })\n .catch((e: unknown) => {\n DEBUG_BUILD && debug.warn(`Error resolving async handler '${handlerKey}' for route`, route, e);\n });\n } else if (Array.isArray(result)) {\n processResolvedRoutes(result, route, currentLocation ?? undefined, capturedSpan);\n }\n}\n\n/**\n * Recursively checks a route for async handlers and sets up Proxies to add discovered child routes to allRoutes when called.\n */\nexport function checkRouteForAsyncHandler(\n route: RouteObject,\n processResolvedRoutes: (\n resolvedRoutes: RouteObject[],\n parentRoute?: RouteObject,\n currentLocation?: Location,\n capturedSpan?: Span,\n ) => void,\n): void {\n // Set up proxies for any functions in the route's handle\n if (route.handle && typeof route.handle === 'object') {\n for (const key of Object.keys(route.handle)) {\n const maybeFn = route.handle[key];\n if (typeof maybeFn === 'function' && !(maybeFn as { __sentry_proxied__?: boolean }).__sentry_proxied__) {\n route.handle[key] = createAsyncHandlerProxy(maybeFn, route, key, processResolvedRoutes);\n }\n }\n }\n\n // Recursively check child routes\n if (Array.isArray(route.children)) {\n for (const child of route.children) {\n checkRouteForAsyncHandler(child, processResolvedRoutes);\n }\n }\n}\n"],"names":["getNavigationContext","WINDOW","DEBUG_BUILD","debug","getActiveRootSpan","addNonEnumerableProperty","isThenable"],"mappings":";;;;;;;AAOA;AACA;AACA;AACA;AACA,SAAS,sBAAsB,GAAoB;AACnD,EAAE,MAAM,UAAA,GAAaA,0BAAoB,EAAE;AAC3C;AACA;AACA,EAAE,IAAI,UAAU,EAAE,UAAU,EAAE;AAC9B,IAAI,OAAO;AACX,MAAM,QAAQ,EAAE,UAAU,CAAC,UAAU;AACrC,MAAM,MAAM,EAAE,EAAE;AAChB,MAAM,IAAI,EAAE,EAAE;AACd,MAAM,KAAK,EAAE,IAAI;AACjB,MAAM,GAAG,EAAE,SAAS;AACpB,KAAK;AACL,EAAE;;AAEF,EAAE,IAAI,OAAOC,cAAA,KAAW,WAAW,EAAE;AACrC,IAAI,IAAI;AACR,MAAM,MAAM,cAAA,GAAiBA,cAAM,CAAC,QAAQ;AAC5C,MAAM,IAAI,cAAc,EAAE;AAC1B,QAAQ,OAAO;AACf,UAAU,QAAQ,EAAE,cAAc,CAAC,QAAQ;AAC3C,UAAU,MAAM,EAAE,cAAc,CAAC,MAAA,IAAU,EAAE;AAC7C,UAAU,IAAI,EAAE,cAAc,CAAC,IAAA,IAAQ,EAAE;AACzC,UAAU,KAAK,EAAE,IAAI;AACrB,UAAU,GAAG,EAAE,SAAS;AACxB,SAAS;AACT,MAAM;AACN,IAAI,EAAE,MAAM;AACZ,MAAMC,0BAAeC,UAAK,CAAC,IAAI,CAAC,iDAAiD,CAAC;AAClF,IAAI;AACJ,EAAE;AACF,EAAE,OAAO,IAAI;AACb;;AAEA;AACA;AACA;AACA;AACA,SAAS,iBAAiB,GAAqB;AAC/C,EAAE,MAAM,UAAA,GAAaH,0BAAoB,EAAE;AAC3C,EAAE,IAAI,UAAU,EAAE;AAClB,IAAI,OAAO,UAAU,CAAC,IAAI;AA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, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
|
+
const core = require('@sentry/core');
|
|
4
|
+
const debugBuild = require('../debug-build.js');
|
|
5
|
+
|
|
3
6
|
// Global variables that these utilities depend on
|
|
4
7
|
let _matchRoutes;
|
|
5
8
|
let _stripBasename = false;
|
|
6
9
|
|
|
10
|
+
// Navigation context stack for nested/concurrent patchRoutesOnNavigation calls.
|
|
11
|
+
// Required because window.location hasn't updated yet when handlers are invoked.
|
|
12
|
+
|
|
13
|
+
const _navigationContextStack = [];
|
|
14
|
+
const MAX_CONTEXT_STACK_SIZE = 10;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Pushes a navigation context and returns a unique token for cleanup.
|
|
18
|
+
* The token uses object identity for uniqueness (no counter needed).
|
|
19
|
+
*/
|
|
20
|
+
function setNavigationContext(targetPath, span) {
|
|
21
|
+
const token = {};
|
|
22
|
+
// Prevent unbounded stack growth - oldest (likely stale) contexts are evicted first
|
|
23
|
+
if (_navigationContextStack.length >= MAX_CONTEXT_STACK_SIZE) {
|
|
24
|
+
debugBuild.DEBUG_BUILD && core.debug.warn('[React Router] Navigation context stack overflow - removing oldest context');
|
|
25
|
+
_navigationContextStack.shift();
|
|
26
|
+
}
|
|
27
|
+
_navigationContextStack.push({ token, targetPath, span });
|
|
28
|
+
return token;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Clears the navigation context if it's on top of the stack (LIFO).
|
|
33
|
+
* If our context is not on top (out-of-order completion), we leave it -
|
|
34
|
+
* it will be cleaned up by overflow protection when the stack fills up.
|
|
35
|
+
*/
|
|
36
|
+
function clearNavigationContext(token) {
|
|
37
|
+
const top = _navigationContextStack[_navigationContextStack.length - 1];
|
|
38
|
+
if (top?.token === token) {
|
|
39
|
+
_navigationContextStack.pop();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Gets the current (most recent) navigation context if inside a patchRoutesOnNavigation call. */
|
|
44
|
+
function getNavigationContext() {
|
|
45
|
+
const length = _navigationContextStack.length;
|
|
46
|
+
// The `?? null` converts undefined (from array access) to null to match return type
|
|
47
|
+
return length > 0 ? (_navigationContextStack[length - 1] ?? null) : null;
|
|
48
|
+
}
|
|
49
|
+
|
|
7
50
|
/**
|
|
8
51
|
* Initialize function to set dependencies that the router utilities need.
|
|
9
52
|
* Must be called before using any of the exported utility functions.
|
|
@@ -273,6 +316,26 @@ function resolveRouteNameAndSource(
|
|
|
273
316
|
return [name || location.pathname, source];
|
|
274
317
|
}
|
|
275
318
|
|
|
319
|
+
/**
|
|
320
|
+
* Gets the active root span if it's a pageload or navigation span.
|
|
321
|
+
*/
|
|
322
|
+
function getActiveRootSpan() {
|
|
323
|
+
const span = core.getActiveSpan();
|
|
324
|
+
const rootSpan = span ? core.getRootSpan(span) : undefined;
|
|
325
|
+
|
|
326
|
+
if (!rootSpan) {
|
|
327
|
+
return undefined;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const op = core.spanToJSON(rootSpan).op;
|
|
331
|
+
|
|
332
|
+
// Only use this root span if it is a pageload or navigation span
|
|
333
|
+
return op === 'navigation' || op === 'pageload' ? rootSpan : undefined;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
exports.clearNavigationContext = clearNavigationContext;
|
|
337
|
+
exports.getActiveRootSpan = getActiveRootSpan;
|
|
338
|
+
exports.getNavigationContext = getNavigationContext;
|
|
276
339
|
exports.getNormalizedName = getNormalizedName;
|
|
277
340
|
exports.getNumberOfUrlSegments = getNumberOfUrlSegments;
|
|
278
341
|
exports.initializeRouterUtils = initializeRouterUtils;
|
|
@@ -283,5 +346,6 @@ exports.prefixWithSlash = prefixWithSlash;
|
|
|
283
346
|
exports.rebuildRoutePathFromAllRoutes = rebuildRoutePathFromAllRoutes;
|
|
284
347
|
exports.resolveRouteNameAndSource = resolveRouteNameAndSource;
|
|
285
348
|
exports.routeIsDescendant = routeIsDescendant;
|
|
349
|
+
exports.setNavigationContext = setNavigationContext;
|
|
286
350
|
exports.transactionNameHasWildcard = transactionNameHasWildcard;
|
|
287
351
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../src/reactrouter-compat-utils/utils.ts"],"sourcesContent":["import type { TransactionSource } from '@sentry/core';\nimport type { Location, MatchRoutes, RouteMatch, RouteObject } from '../types';\n\n// Global variables that these utilities depend on\nlet _matchRoutes: MatchRoutes;\nlet _stripBasename: boolean = false;\n\n/**\n * Initialize function to set dependencies that the router utilities need.\n * Must be called before using any of the exported utility functions.\n */\nexport function initializeRouterUtils(matchRoutes: MatchRoutes, stripBasename: boolean = false): void {\n _matchRoutes = matchRoutes;\n _stripBasename = stripBasename;\n}\n\n// Helper functions\nfunction pickPath(match: RouteMatch): string {\n return trimWildcard(match.route.path || '');\n}\n\nfunction pickSplat(match: RouteMatch): string {\n return match.params['*'] || '';\n}\n\nfunction trimWildcard(path: string): string {\n return path[path.length - 1] === '*' ? path.slice(0, -1) : path;\n}\n\nfunction trimSlash(path: string): string {\n return path[path.length - 1] === '/' ? path.slice(0, -1) : path;\n}\n\n/**\n * Checks if a path ends with a wildcard character (*).\n */\nexport function pathEndsWithWildcard(path: string): boolean {\n return path.endsWith('*');\n}\n\n/** Checks if transaction name has wildcard (/* or ends with *). */\nexport function transactionNameHasWildcard(name: string): boolean {\n return name.includes('/*') || name.endsWith('*');\n}\n\n/**\n * Checks if a path is a wildcard and has child routes.\n */\nexport function pathIsWildcardAndHasChildren(path: string, branch: RouteMatch<string>): boolean {\n return (pathEndsWithWildcard(path) && !!branch.route.children?.length) || false;\n}\n\n/** Check if route is in descendant route (<Routes> within <Routes>) */\nexport function routeIsDescendant(route: RouteObject): boolean {\n return !!(!route.children && route.element && route.path?.endsWith('/*'));\n}\n\nfunction sendIndexPath(pathBuilder: string, pathname: string, basename: string): [string, TransactionSource] {\n const reconstructedPath =\n pathBuilder && pathBuilder.length > 0\n ? pathBuilder\n : _stripBasename\n ? stripBasenameFromPathname(pathname, basename)\n : pathname;\n\n let formattedPath =\n // If the path ends with a wildcard suffix, remove both the slash and the asterisk\n reconstructedPath.slice(-2) === '/*' ? reconstructedPath.slice(0, -2) : reconstructedPath;\n\n // If the path ends with a slash, remove it (but keep single '/')\n if (formattedPath.length > 1 && formattedPath[formattedPath.length - 1] === '/') {\n formattedPath = formattedPath.slice(0, -1);\n }\n\n return [formattedPath, 'route'];\n}\n\n/**\n * Returns the number of URL segments in the given URL string.\n * Splits at '/' or '\\/' to handle regex URLs correctly.\n *\n * @param url - The URL string to segment.\n * @returns The number of segments in the URL.\n */\nexport function getNumberOfUrlSegments(url: string): number {\n // split at '/' or at '\\/' to split regex urls correctly\n return url.split(/\\\\?\\//).filter(s => s.length > 0 && s !== ',').length;\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\n// Exported utility functions\n\n/**\n * Ensures a path string starts with a forward slash.\n */\nexport function prefixWithSlash(path: string): string {\n return path[0] === '/' ? path : `/${path}`;\n}\n\n/**\n * Rebuilds the route path from all available routes by matching against the current location.\n */\nexport function rebuildRoutePathFromAllRoutes(allRoutes: RouteObject[], location: Location): string {\n const matchedRoutes = _matchRoutes(allRoutes, location) as RouteMatch[];\n\n if (!matchedRoutes || matchedRoutes.length === 0) {\n return '';\n }\n\n for (const match of matchedRoutes) {\n if (match.route.path && match.route.path !== '*') {\n const path = pickPath(match);\n const strippedPath = stripBasenameFromPathname(location.pathname, prefixWithSlash(match.pathnameBase));\n\n if (location.pathname === strippedPath) {\n return trimSlash(strippedPath);\n }\n\n return trimSlash(\n trimSlash(path || '') +\n prefixWithSlash(\n rebuildRoutePathFromAllRoutes(\n allRoutes.filter(route => route !== match.route),\n {\n pathname: strippedPath,\n },\n ),\n ),\n );\n }\n }\n\n return '';\n}\n\n/**\n * Checks if the current location is inside a descendant route (route with splat parameter).\n */\nexport function locationIsInsideDescendantRoute(location: Location, routes: RouteObject[]): boolean {\n const matchedRoutes = _matchRoutes(routes, location) as RouteMatch[];\n\n if (matchedRoutes) {\n for (const match of matchedRoutes) {\n if (routeIsDescendant(match.route) && pickSplat(match)) {\n return true;\n }\n }\n }\n\n return false;\n}\n\n/**\n * Returns a fallback transaction name from location pathname.\n */\nfunction getFallbackTransactionName(location: Location, basename: string): string {\n return _stripBasename ? stripBasenameFromPathname(location.pathname, basename) : location.pathname || '';\n}\n\n/**\n * Gets a normalized route name and transaction source from the current routes and location.\n */\nexport function 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 if (!branches) {\n return [getFallbackTransactionName(location, basename), 'url'];\n }\n\n let pathBuilder = '';\n\n for (const branch of branches) {\n const route = branch.route;\n if (!route) {\n continue;\n }\n\n // Early return for index routes\n if (route.index) {\n return sendIndexPath(pathBuilder, branch.pathname, basename);\n }\n\n const path = route.path;\n if (!path || pathIsWildcardAndHasChildren(path, branch)) {\n continue;\n }\n\n // Build the route path\n const newPath = path[0] === '/' || pathBuilder[pathBuilder.length - 1] === '/' ? path : `/${path}`;\n pathBuilder = trimSlash(pathBuilder) + prefixWithSlash(newPath);\n\n // Check if this path matches the current location\n if (trimSlash(location.pathname) !== trimSlash(basename + branch.pathname)) {\n continue;\n }\n\n // Check if this is a parameterized route like /stores/:storeId/products/:productId\n if (\n getNumberOfUrlSegments(pathBuilder) !== getNumberOfUrlSegments(branch.pathname) &&\n !pathEndsWithWildcard(pathBuilder)\n ) {\n return [(_stripBasename ? '' : basename) + newPath, 'route'];\n }\n\n // Handle wildcard routes with children - strip trailing wildcard\n if (pathIsWildcardAndHasChildren(pathBuilder, branch)) {\n pathBuilder = pathBuilder.slice(0, -1);\n }\n\n return [(_stripBasename ? '' : basename) + pathBuilder, 'route'];\n }\n\n // Fallback when no matching route found\n return [getFallbackTransactionName(location, basename), 'url'];\n}\n\n/**\n * Shared helper function to resolve route name and source\n */\nexport function resolveRouteNameAndSource(\n location: Location,\n routes: RouteObject[],\n allRoutes: RouteObject[],\n branches: RouteMatch[],\n basename: string = '',\n): [string, TransactionSource] {\n let name: string | undefined;\n let source: TransactionSource = 'url';\n\n const isInDescendantRoute = locationIsInsideDescendantRoute(location, allRoutes);\n\n if (isInDescendantRoute) {\n name = prefixWithSlash(rebuildRoutePathFromAllRoutes(allRoutes, location));\n source = 'route';\n }\n\n if (!isInDescendantRoute || !name) {\n [name, source] = getNormalizedName(routes, location, branches, basename);\n }\n\n return [name || location.pathname, source];\n}\n"],"names":[],"mappings":";;AAGA;AACA,IAAI,YAAY;AAChB,IAAI,cAAc,GAAY,KAAK;;AAEnC;AACA;AACA;AACA;AACO,SAAS,qBAAqB,CAAC,WAAW,EAAe,aAAa,GAAY,KAAK,EAAQ;AACtG,EAAE,YAAA,GAAe,WAAW;AAC5B,EAAE,cAAA,GAAiB,aAAa;AAChC;;AAEA;AACA,SAAS,QAAQ,CAAC,KAAK,EAAsB;AAC7C,EAAE,OAAO,YAAY,CAAC,KAAK,CAAC,KAAK,CAAC,IAAA,IAAQ,EAAE,CAAC;AAC7C;;AAEA,SAAS,SAAS,CAAC,KAAK,EAAsB;AAC9C,EAAE,OAAO,KAAK,CAAC,MAAM,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AA,QAAA,IAAA,WAAA,EAAA,OAAA,CAAA;AACA,EAAA;;AAEA;AACA,EAAA,OAAA,CAAA,0BAAA,CAAA,QAAA,EAAA,QAAA,CAAA,EAAA,KAAA,CAAA;AACA;;AAEA;AACA;AACA;AACA,SAAA,yBAAA;AACA,EAAA,QAAA;AACA,EAAA,MAAA;AACA,EAAA,SAAA;AACA,EAAA,QAAA;AACA,EAAA,QAAA,GAAA,EAAA;AACA,EAAA;AACA,EAAA,IAAA,IAAA;AACA,EAAA,IAAA,MAAA,GAAA,KAAA;;AAEA,EAAA,MAAA,mBAAA,GAAA,+BAAA,CAAA,QAAA,EAAA,SAAA,CAAA;;AAEA,EAAA,IAAA,mBAAA,EAAA;AACA,IAAA,IAAA,GAAA,eAAA,CAAA,6BAAA,CAAA,SAAA,EAAA,QAAA,CAAA,CAAA;AACA,IAAA,MAAA,GAAA,OAAA;AACA,EAAA;;AAEA,EAAA,IAAA,CAAA,mBAAA,IAAA,CAAA,IAAA,EAAA;AACA,IAAA,CAAA,IAAA,EAAA,MAAA,CAAA,GAAA,iBAAA,CAAA,MAAA,EAAA,QAAA,EAAA,QAAA,EAAA,QAAA,CAAA;AACA,EAAA;;AAEA,EAAA,OAAA,CAAA,IAAA,IAAA,QAAA,CAAA,QAAA,EAAA,MAAA,CAAA;AACA;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../src/reactrouter-compat-utils/utils.ts"],"sourcesContent":["import type { Span, TransactionSource } from '@sentry/core';\nimport { debug, getActiveSpan, getRootSpan, spanToJSON } from '@sentry/core';\nimport { DEBUG_BUILD } from '../debug-build';\nimport type { Location, MatchRoutes, RouteMatch, RouteObject } from '../types';\n\n// Global variables that these utilities depend on\nlet _matchRoutes: MatchRoutes;\nlet _stripBasename: boolean = false;\n\n// Navigation context stack for nested/concurrent patchRoutesOnNavigation calls.\n// Required because window.location hasn't updated yet when handlers are invoked.\ninterface NavigationContext {\n token: object;\n targetPath: string | undefined;\n span: Span | undefined;\n}\n\nconst _navigationContextStack: NavigationContext[] = [];\nconst MAX_CONTEXT_STACK_SIZE = 10;\n\n/**\n * Pushes a navigation context and returns a unique token for cleanup.\n * The token uses object identity for uniqueness (no counter needed).\n */\nexport function setNavigationContext(targetPath: string | undefined, span: Span | undefined): object {\n const token = {};\n // Prevent unbounded stack growth - oldest (likely stale) contexts are evicted first\n if (_navigationContextStack.length >= MAX_CONTEXT_STACK_SIZE) {\n DEBUG_BUILD && debug.warn('[React Router] Navigation context stack overflow - removing oldest context');\n _navigationContextStack.shift();\n }\n _navigationContextStack.push({ token, targetPath, span });\n return token;\n}\n\n/**\n * Clears the navigation context if it's on top of the stack (LIFO).\n * If our context is not on top (out-of-order completion), we leave it -\n * it will be cleaned up by overflow protection when the stack fills up.\n */\nexport function clearNavigationContext(token: object): void {\n const top = _navigationContextStack[_navigationContextStack.length - 1];\n if (top?.token === token) {\n _navigationContextStack.pop();\n }\n}\n\n/** Gets the current (most recent) navigation context if inside a patchRoutesOnNavigation call. */\nexport function getNavigationContext(): NavigationContext | null {\n const length = _navigationContextStack.length;\n // The `?? null` converts undefined (from array access) to null to match return type\n return length > 0 ? (_navigationContextStack[length - 1] ?? null) : null;\n}\n\n/**\n * Initialize function to set dependencies that the router utilities need.\n * Must be called before using any of the exported utility functions.\n */\nexport function initializeRouterUtils(matchRoutes: MatchRoutes, stripBasename: boolean = false): void {\n _matchRoutes = matchRoutes;\n _stripBasename = stripBasename;\n}\n\n// Helper functions\nfunction pickPath(match: RouteMatch): string {\n return trimWildcard(match.route.path || '');\n}\n\nfunction pickSplat(match: RouteMatch): string {\n return match.params['*'] || '';\n}\n\nfunction trimWildcard(path: string): string {\n return path[path.length - 1] === '*' ? path.slice(0, -1) : path;\n}\n\nfunction trimSlash(path: string): string {\n return path[path.length - 1] === '/' ? path.slice(0, -1) : path;\n}\n\n/**\n * Checks if a path ends with a wildcard character (*).\n */\nexport function pathEndsWithWildcard(path: string): boolean {\n return path.endsWith('*');\n}\n\n/** Checks if transaction name has wildcard (/* or ends with *). */\nexport function transactionNameHasWildcard(name: string): boolean {\n return name.includes('/*') || name.endsWith('*');\n}\n\n/**\n * Checks if a path is a wildcard and has child routes.\n */\nexport function pathIsWildcardAndHasChildren(path: string, branch: RouteMatch<string>): boolean {\n return (pathEndsWithWildcard(path) && !!branch.route.children?.length) || false;\n}\n\n/** Check if route is in descendant route (<Routes> within <Routes>) */\nexport function routeIsDescendant(route: RouteObject): boolean {\n return !!(!route.children && route.element && route.path?.endsWith('/*'));\n}\n\nfunction sendIndexPath(pathBuilder: string, pathname: string, basename: string): [string, TransactionSource] {\n const reconstructedPath =\n pathBuilder && pathBuilder.length > 0\n ? pathBuilder\n : _stripBasename\n ? stripBasenameFromPathname(pathname, basename)\n : pathname;\n\n let formattedPath =\n // If the path ends with a wildcard suffix, remove both the slash and the asterisk\n reconstructedPath.slice(-2) === '/*' ? reconstructedPath.slice(0, -2) : reconstructedPath;\n\n // If the path ends with a slash, remove it (but keep single '/')\n if (formattedPath.length > 1 && formattedPath[formattedPath.length - 1] === '/') {\n formattedPath = formattedPath.slice(0, -1);\n }\n\n return [formattedPath, 'route'];\n}\n\n/**\n * Returns the number of URL segments in the given URL string.\n * Splits at '/' or '\\/' to handle regex URLs correctly.\n *\n * @param url - The URL string to segment.\n * @returns The number of segments in the URL.\n */\nexport function getNumberOfUrlSegments(url: string): number {\n // split at '/' or at '\\/' to split regex urls correctly\n return url.split(/\\\\?\\//).filter(s => s.length > 0 && s !== ',').length;\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\n// Exported utility functions\n\n/**\n * Ensures a path string starts with a forward slash.\n */\nexport function prefixWithSlash(path: string): string {\n return path[0] === '/' ? path : `/${path}`;\n}\n\n/**\n * Rebuilds the route path from all available routes by matching against the current location.\n */\nexport function rebuildRoutePathFromAllRoutes(allRoutes: RouteObject[], location: Location): string {\n const matchedRoutes = _matchRoutes(allRoutes, location) as RouteMatch[];\n\n if (!matchedRoutes || matchedRoutes.length === 0) {\n return '';\n }\n\n for (const match of matchedRoutes) {\n if (match.route.path && match.route.path !== '*') {\n const path = pickPath(match);\n const strippedPath = stripBasenameFromPathname(location.pathname, prefixWithSlash(match.pathnameBase));\n\n if (location.pathname === strippedPath) {\n return trimSlash(strippedPath);\n }\n\n return trimSlash(\n trimSlash(path || '') +\n prefixWithSlash(\n rebuildRoutePathFromAllRoutes(\n allRoutes.filter(route => route !== match.route),\n {\n pathname: strippedPath,\n },\n ),\n ),\n );\n }\n }\n\n return '';\n}\n\n/**\n * Checks if the current location is inside a descendant route (route with splat parameter).\n */\nexport function locationIsInsideDescendantRoute(location: Location, routes: RouteObject[]): boolean {\n const matchedRoutes = _matchRoutes(routes, location) as RouteMatch[];\n\n if (matchedRoutes) {\n for (const match of matchedRoutes) {\n if (routeIsDescendant(match.route) && pickSplat(match)) {\n return true;\n }\n }\n }\n\n return false;\n}\n\n/**\n * Returns a fallback transaction name from location pathname.\n */\nfunction getFallbackTransactionName(location: Location, basename: string): string {\n return _stripBasename ? stripBasenameFromPathname(location.pathname, basename) : location.pathname || '';\n}\n\n/**\n * Gets a normalized route name and transaction source from the current routes and location.\n */\nexport function 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 if (!branches) {\n return [getFallbackTransactionName(location, basename), 'url'];\n }\n\n let pathBuilder = '';\n\n for (const branch of branches) {\n const route = branch.route;\n if (!route) {\n continue;\n }\n\n // Early return for index routes\n if (route.index) {\n return sendIndexPath(pathBuilder, branch.pathname, basename);\n }\n\n const path = route.path;\n if (!path || pathIsWildcardAndHasChildren(path, branch)) {\n continue;\n }\n\n // Build the route path\n const newPath = path[0] === '/' || pathBuilder[pathBuilder.length - 1] === '/' ? path : `/${path}`;\n pathBuilder = trimSlash(pathBuilder) + prefixWithSlash(newPath);\n\n // Check if this path matches the current location\n if (trimSlash(location.pathname) !== trimSlash(basename + branch.pathname)) {\n continue;\n }\n\n // Check if this is a parameterized route like /stores/:storeId/products/:productId\n if (\n getNumberOfUrlSegments(pathBuilder) !== getNumberOfUrlSegments(branch.pathname) &&\n !pathEndsWithWildcard(pathBuilder)\n ) {\n return [(_stripBasename ? '' : basename) + newPath, 'route'];\n }\n\n // Handle wildcard routes with children - strip trailing wildcard\n if (pathIsWildcardAndHasChildren(pathBuilder, branch)) {\n pathBuilder = pathBuilder.slice(0, -1);\n }\n\n return [(_stripBasename ? '' : basename) + pathBuilder, 'route'];\n }\n\n // Fallback when no matching route found\n return [getFallbackTransactionName(location, basename), 'url'];\n}\n\n/**\n * Shared helper function to resolve route name and source\n */\nexport function resolveRouteNameAndSource(\n location: Location,\n routes: RouteObject[],\n allRoutes: RouteObject[],\n branches: RouteMatch[],\n basename: string = '',\n): [string, TransactionSource] {\n let name: string | undefined;\n let source: TransactionSource = 'url';\n\n const isInDescendantRoute = locationIsInsideDescendantRoute(location, allRoutes);\n\n if (isInDescendantRoute) {\n name = prefixWithSlash(rebuildRoutePathFromAllRoutes(allRoutes, location));\n source = 'route';\n }\n\n if (!isInDescendantRoute || !name) {\n [name, source] = getNormalizedName(routes, location, branches, basename);\n }\n\n return [name || location.pathname, source];\n}\n\n/**\n * Gets the active root span if it's a pageload or navigation span.\n */\nexport function 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":["DEBUG_BUILD","debug","getActiveSpan","getRootSpan","spanToJSON"],"mappings":";;;;;AAKA;AACA,IAAI,YAAY;AAChB,IAAI,cAAc,GAAY,KAAK;;AAEnC;AACA;;AAOA,MAAM,uBAAuB,GAAwB,EAAE;AACvD,MAAM,sBAAA,GAAyB,EAAE;;AAEjC;AACA;AACA;AACA;AACO,SAAS,oBAAoB,CAAC,UAAU,EAAsB,IAAI,EAA4B;AACrG,EAAE,MAAM,KAAA,GAAQ,EAAE;AAClB;AACA,EAAE,IAAI,uBAAuB,CAAC,MAAA,IAAU,sBAAsB,EAAE;AAChE,IAAIA,0BAAeC,UAAK,CAAC,IAAI,CAAC,4EAA4E,CAAC;AAC3G,IAAI,uBAAuB,CAAC,KAAK,EAAE;AACnC,EAAE;AACF,EAAE,uBAAuB,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,IAAA,EAAM,CAAC;AAC3D,EAAE,OAAO,KAAK;AACd;;AAEA;AACA;AACA;AACA;AACA;AACO,SAAS,sBAAsB,CAAC,KAAK,EAAgB;AAC5D,EAAE,MAAM,GAAA,GAAM,uBAAuB,CAAC,uBAAuB,CAAC,MAAA,GAAS,CAAC,CAAC;AACzE,EAAE,IAAI,GAAG,EAAE,KAAA,KAAU,KAAK,EAAE;AAC5B,IAAI,uBAAuB,CAAC,GAAG,EAAE;AACjC,EAAE;AACF;;AAEA;AACO,SAAS,oBAAoB,GAA6B;AACjE,EAAE,MAAM,MAAA,GAAS,uBAAuB,CAAC,MAAM;AAC/C;AACA,EAAE,OAAO,MAAA,GAAS,CAAA,IAAK,u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,CAAA;AACA;;AAEA;AACA;AACA;AACA,SAAA,iBAAA,GAAA;AACA,EAAA,MAAA,IAAA,GAAAC,kBAAA,EAAA;AACA,EAAA,MAAA,QAAA,GAAA,IAAA,GAAAC,gBAAA,CAAA,IAAA,CAAA,GAAA,SAAA;;AAEA,EAAA,IAAA,CAAA,QAAA,EAAA;AACA,IAAA,OAAA,SAAA;AACA,EAAA;;AAEA,EAAA,MAAA,EAAA,GAAAC,eAAA,CAAA,QAAA,CAAA,CAAA,EAAA;;AAEA;AACA,EAAA,OAAA,EAAA,KAAA,YAAA,IAAA,EAAA,KAAA,UAAA,GAAA,QAAA,GAAA,SAAA;AACA;;;;;;;;;;;;;;;;;;"}
|
|
@@ -2,6 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
|
|
3
3
|
const instrumentation = require('./reactrouter-compat-utils/instrumentation.js');
|
|
4
4
|
require('@sentry/core');
|
|
5
|
+
require('@sentry/browser');
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* A browser tracing integration that uses React Router v6 to instrument navigations.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactrouterv6.js","sources":["../../src/reactrouterv6.tsx"],"sourcesContent":["import type { browserTracingIntegration } from '@sentry/browser';\nimport type { Integration } from '@sentry/core';\nimport type { ReactRouterOptions } from './reactrouter-compat-utils';\nimport {\n createReactRouterV6CompatibleTracingIntegration,\n createV6CompatibleWithSentryReactRouterRouting,\n createV6CompatibleWrapCreateBrowserRouter,\n createV6CompatibleWrapCreateMemoryRouter,\n createV6CompatibleWrapUseRoutes,\n} from './reactrouter-compat-utils';\nimport type { CreateRouterFunction, Router, RouterState, UseRoutes } from './types';\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 return createReactRouterV6CompatibleTracingIntegration(options, '6');\n}\n\n/**\n * A wrapper function that adds Sentry routing instrumentation to a React Router v6 useRoutes hook.\n * This is used to automatically capture route changes as transactions when using the useRoutes hook.\n */\nexport function wrapUseRoutesV6(origUseRoutes: UseRoutes): UseRoutes {\n return createV6CompatibleWrapUseRoutes(origUseRoutes, '6');\n}\n\n/**\n * A wrapper function that adds Sentry routing instrumentation to a React Router v6 createBrowserRouter function.\n * This is used to automatically capture route changes as transactions when using the createBrowserRouter API.\n */\nexport function wrapCreateBrowserRouterV6<\n TState extends RouterState = RouterState,\n TRouter extends Router<TState> = Router<TState>,\n>(createRouterFunction: CreateRouterFunction<TState, TRouter>): CreateRouterFunction<TState, TRouter> {\n return createV6CompatibleWrapCreateBrowserRouter(createRouterFunction, '6');\n}\n\n/**\n * A wrapper function that adds Sentry routing instrumentation to a React Router v6 createMemoryRouter function.\n * This is used to automatically capture route changes as transactions when using the createMemoryRouter API.\n * The difference between createBrowserRouter and createMemoryRouter is that with createMemoryRouter,\n * optional `initialEntries` are also taken into account.\n */\nexport function wrapCreateMemoryRouterV6<\n TState extends RouterState = RouterState,\n TRouter extends Router<TState> = Router<TState>,\n>(createMemoryRouterFunction: CreateRouterFunction<TState, TRouter>): CreateRouterFunction<TState, TRouter> {\n return createV6CompatibleWrapCreateMemoryRouter(createMemoryRouterFunction, '6');\n}\n\n/**\n * A higher-order component that adds Sentry routing instrumentation to a React Router v6 Route component.\n * This is used to automatically capture route changes as transactions.\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 return createV6CompatibleWithSentryReactRouterRouting<P, R>(routes, '6');\n}\n"],"names":["createReactRouterV6CompatibleTracingIntegration","createV6CompatibleWrapUseRoutes","createV6CompatibleWrapCreateBrowserRouter","createV6CompatibleWrapCreateMemoryRouter","createV6CompatibleWithSentryReactRouterRouting"],"mappings":"
|
|
1
|
+
{"version":3,"file":"reactrouterv6.js","sources":["../../src/reactrouterv6.tsx"],"sourcesContent":["import type { browserTracingIntegration } from '@sentry/browser';\nimport type { Integration } from '@sentry/core';\nimport type { ReactRouterOptions } from './reactrouter-compat-utils';\nimport {\n createReactRouterV6CompatibleTracingIntegration,\n createV6CompatibleWithSentryReactRouterRouting,\n createV6CompatibleWrapCreateBrowserRouter,\n createV6CompatibleWrapCreateMemoryRouter,\n createV6CompatibleWrapUseRoutes,\n} from './reactrouter-compat-utils';\nimport type { CreateRouterFunction, Router, RouterState, UseRoutes } from './types';\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 return createReactRouterV6CompatibleTracingIntegration(options, '6');\n}\n\n/**\n * A wrapper function that adds Sentry routing instrumentation to a React Router v6 useRoutes hook.\n * This is used to automatically capture route changes as transactions when using the useRoutes hook.\n */\nexport function wrapUseRoutesV6(origUseRoutes: UseRoutes): UseRoutes {\n return createV6CompatibleWrapUseRoutes(origUseRoutes, '6');\n}\n\n/**\n * A wrapper function that adds Sentry routing instrumentation to a React Router v6 createBrowserRouter function.\n * This is used to automatically capture route changes as transactions when using the createBrowserRouter API.\n */\nexport function wrapCreateBrowserRouterV6<\n TState extends RouterState = RouterState,\n TRouter extends Router<TState> = Router<TState>,\n>(createRouterFunction: CreateRouterFunction<TState, TRouter>): CreateRouterFunction<TState, TRouter> {\n return createV6CompatibleWrapCreateBrowserRouter(createRouterFunction, '6');\n}\n\n/**\n * A wrapper function that adds Sentry routing instrumentation to a React Router v6 createMemoryRouter function.\n * This is used to automatically capture route changes as transactions when using the createMemoryRouter API.\n * The difference between createBrowserRouter and createMemoryRouter is that with createMemoryRouter,\n * optional `initialEntries` are also taken into account.\n */\nexport function wrapCreateMemoryRouterV6<\n TState extends RouterState = RouterState,\n TRouter extends Router<TState> = Router<TState>,\n>(createMemoryRouterFunction: CreateRouterFunction<TState, TRouter>): CreateRouterFunction<TState, TRouter> {\n return createV6CompatibleWrapCreateMemoryRouter(createMemoryRouterFunction, '6');\n}\n\n/**\n * A higher-order component that adds Sentry routing instrumentation to a React Router v6 Route component.\n * This is used to automatically capture route changes as transactions.\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 return createV6CompatibleWithSentryReactRouterRouting<P, R>(routes, '6');\n}\n"],"names":["createReactRouterV6CompatibleTracingIntegration","createV6CompatibleWrapUseRoutes","createV6CompatibleWrapCreateBrowserRouter","createV6CompatibleWrapCreateMemoryRouter","createV6CompatibleWithSentryReactRouterRouting"],"mappings":";;;;;;AAYA;AACA;AACA;AACA;AACO,SAAS,sCAAsC;AACtD,EAAE,OAAO;AACT,EAAe;AACf,EAAE,OAAOA,+DAA+C,CAAC,OAAO,EAAE,GAAG,CAAC;AACtE;;AAEA;AACA;AACA;AACA;AACO,SAAS,eAAe,CAAC,aAAa,EAAwB;AACrE,EAAE,OAAOC,+CAA+B,CAAC,aAAa,EAAE,GAAG,CAAC;AAC5D;;AAEA;AACA;AACA;AACA;AACO,SAAS;;AAGhB,CAAE,oBAAoB,EAAgF;AACtG,EAAE,OAAOC,yDAAyC,CAAC,oBAAoB,EAAE,GAAG,CAAC;AAC7E;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS;;AAGhB,CAAE,0BAA0B,EAAgF;AAC5G,EAAE,OAAOC,wDAAwC,CAAC,0BAA0B,EAAE,GAAG,CAAC;AAClF;;AAEA;AACA;AACA;AACA;AACA;AACO,SAAS,8BAA8B,CAAuD,MAAM,EAAQ;AACnH,EAAE,OAAOC,8DAA8C,CAAO,MAAM,EAAE,GAAG,CAAC;AAC1E;;;;;;;;"}
|
|
@@ -2,6 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
|
|
3
3
|
const instrumentation = require('./reactrouter-compat-utils/instrumentation.js');
|
|
4
4
|
require('@sentry/core');
|
|
5
|
+
require('@sentry/browser');
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* A browser tracing integration that uses React Router v7 to instrument navigations.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactrouterv7.js","sources":["../../src/reactrouterv7.tsx"],"sourcesContent":["// React Router v7 uses the same integration as v6\nimport type { browserTracingIntegration } from '@sentry/browser';\nimport type { Integration } from '@sentry/core';\nimport type { ReactRouterOptions } from './reactrouter-compat-utils';\nimport {\n createReactRouterV6CompatibleTracingIntegration,\n createV6CompatibleWithSentryReactRouterRouting,\n createV6CompatibleWrapCreateBrowserRouter,\n createV6CompatibleWrapCreateMemoryRouter,\n createV6CompatibleWrapUseRoutes,\n} from './reactrouter-compat-utils';\nimport type { CreateRouterFunction, Router, RouterState, UseRoutes } from './types';\n\n/**\n * A browser tracing integration that uses React Router v7 to instrument navigations.\n * Expects `useEffect`, `useLocation`, `useNavigationType`, `createRoutesFromChildren` and `matchRoutes` to be passed as options.\n */\nexport function reactRouterV7BrowserTracingIntegration(\n options: Parameters<typeof browserTracingIntegration>[0] & ReactRouterOptions,\n): Integration {\n return createReactRouterV6CompatibleTracingIntegration(options, '7');\n}\n\n/**\n * A higher-order component that adds Sentry routing instrumentation to a React Router v7 Route component.\n * This is used to automatically capture route changes as transactions.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function withSentryReactRouterV7Routing<P extends Record<string, any>, R extends React.FC<P>>(routes: R): R {\n return createV6CompatibleWithSentryReactRouterRouting<P, R>(routes, '7');\n}\n\n/**\n * A wrapper function that adds Sentry routing instrumentation to a React Router v7 createBrowserRouter function.\n * This is used to automatically capture route changes as transactions when using the createBrowserRouter API.\n */\nexport function wrapCreateBrowserRouterV7<\n TState extends RouterState = RouterState,\n TRouter extends Router<TState> = Router<TState>,\n>(createRouterFunction: CreateRouterFunction<TState, TRouter>): CreateRouterFunction<TState, TRouter> {\n return createV6CompatibleWrapCreateBrowserRouter(createRouterFunction, '7');\n}\n\n/**\n * A wrapper function that adds Sentry routing instrumentation to a React Router v7 createMemoryRouter function.\n * This is used to automatically capture route changes as transactions when using the createMemoryRouter API.\n * The difference between createBrowserRouter and createMemoryRouter is that with createMemoryRouter,\n * optional `initialEntries` are also taken into account.\n */\nexport function wrapCreateMemoryRouterV7<\n TState extends RouterState = RouterState,\n TRouter extends Router<TState> = Router<TState>,\n>(createMemoryRouterFunction: CreateRouterFunction<TState, TRouter>): CreateRouterFunction<TState, TRouter> {\n return createV6CompatibleWrapCreateMemoryRouter(createMemoryRouterFunction, '7');\n}\n\n/**\n * A wrapper function that adds Sentry routing instrumentation to a React Router v7 useRoutes hook.\n * This is used to automatically capture route changes as transactions when using the useRoutes hook.\n */\nexport function wrapUseRoutesV7(origUseRoutes: UseRoutes): UseRoutes {\n return createV6CompatibleWrapUseRoutes(origUseRoutes, '7');\n}\n"],"names":["createReactRouterV6CompatibleTracingIntegration","createV6CompatibleWithSentryReactRouterRouting","createV6CompatibleWrapCreateBrowserRouter","createV6CompatibleWrapCreateMemoryRouter","createV6CompatibleWrapUseRoutes"],"mappings":"
|
|
1
|
+
{"version":3,"file":"reactrouterv7.js","sources":["../../src/reactrouterv7.tsx"],"sourcesContent":["// React Router v7 uses the same integration as v6\nimport type { browserTracingIntegration } from '@sentry/browser';\nimport type { Integration } from '@sentry/core';\nimport type { ReactRouterOptions } from './reactrouter-compat-utils';\nimport {\n createReactRouterV6CompatibleTracingIntegration,\n createV6CompatibleWithSentryReactRouterRouting,\n createV6CompatibleWrapCreateBrowserRouter,\n createV6CompatibleWrapCreateMemoryRouter,\n createV6CompatibleWrapUseRoutes,\n} from './reactrouter-compat-utils';\nimport type { CreateRouterFunction, Router, RouterState, UseRoutes } from './types';\n\n/**\n * A browser tracing integration that uses React Router v7 to instrument navigations.\n * Expects `useEffect`, `useLocation`, `useNavigationType`, `createRoutesFromChildren` and `matchRoutes` to be passed as options.\n */\nexport function reactRouterV7BrowserTracingIntegration(\n options: Parameters<typeof browserTracingIntegration>[0] & ReactRouterOptions,\n): Integration {\n return createReactRouterV6CompatibleTracingIntegration(options, '7');\n}\n\n/**\n * A higher-order component that adds Sentry routing instrumentation to a React Router v7 Route component.\n * This is used to automatically capture route changes as transactions.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function withSentryReactRouterV7Routing<P extends Record<string, any>, R extends React.FC<P>>(routes: R): R {\n return createV6CompatibleWithSentryReactRouterRouting<P, R>(routes, '7');\n}\n\n/**\n * A wrapper function that adds Sentry routing instrumentation to a React Router v7 createBrowserRouter function.\n * This is used to automatically capture route changes as transactions when using the createBrowserRouter API.\n */\nexport function wrapCreateBrowserRouterV7<\n TState extends RouterState = RouterState,\n TRouter extends Router<TState> = Router<TState>,\n>(createRouterFunction: CreateRouterFunction<TState, TRouter>): CreateRouterFunction<TState, TRouter> {\n return createV6CompatibleWrapCreateBrowserRouter(createRouterFunction, '7');\n}\n\n/**\n * A wrapper function that adds Sentry routing instrumentation to a React Router v7 createMemoryRouter function.\n * This is used to automatically capture route changes as transactions when using the createMemoryRouter API.\n * The difference between createBrowserRouter and createMemoryRouter is that with createMemoryRouter,\n * optional `initialEntries` are also taken into account.\n */\nexport function wrapCreateMemoryRouterV7<\n TState extends RouterState = RouterState,\n TRouter extends Router<TState> = Router<TState>,\n>(createMemoryRouterFunction: CreateRouterFunction<TState, TRouter>): CreateRouterFunction<TState, TRouter> {\n return createV6CompatibleWrapCreateMemoryRouter(createMemoryRouterFunction, '7');\n}\n\n/**\n * A wrapper function that adds Sentry routing instrumentation to a React Router v7 useRoutes hook.\n * This is used to automatically capture route changes as transactions when using the useRoutes hook.\n */\nexport function wrapUseRoutesV7(origUseRoutes: UseRoutes): UseRoutes {\n return createV6CompatibleWrapUseRoutes(origUseRoutes, '7');\n}\n"],"names":["createReactRouterV6CompatibleTracingIntegration","createV6CompatibleWithSentryReactRouterRouting","createV6CompatibleWrapCreateBrowserRouter","createV6CompatibleWrapCreateMemoryRouter","createV6CompatibleWrapUseRoutes"],"mappings":";;;;;;AAaA;AACA;AACA;AACA;AACO,SAAS,sCAAsC;AACtD,EAAE,OAAO;AACT,EAAe;AACf,EAAE,OAAOA,+DAA+C,CAAC,OAAO,EAAE,GAAG,CAAC;AACtE;;AAEA;AACA;AACA;AACA;AACA;AACO,SAAS,8BAA8B,CAAuD,MAAM,EAAQ;AACnH,EAAE,OAAOC,8DAA8C,CAAO,MAAM,EAAE,GAAG,CAAC;AAC1E;;AAEA;AACA;AACA;AACA;AACO,SAAS;;AAGhB,CAAE,oBAAoB,EAAgF;AACtG,EAAE,OAAOC,yDAAyC,CAAC,oBAAoB,EAAE,GAAG,CAAC;AAC7E;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS;;AAGhB,CAAE,0BAA0B,EAAgF;AAC5G,EAAE,OAAOC,wDAAwC,CAAC,0BAA0B,EAAE,GAAG,CAAC;AAClF;;AAEA;AACA;AACA;AACA;AACO,SAAS,eAAe,CAAC,aAAa,EAAwB;AACrE,EAAE,OAAOC,+CAA+B,CAAC,aAAa,EAAE,GAAG,CAAC;AAC5D;;;;;;;;"}
|
package/build/esm/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"type":"module","version":"10.
|
|
1
|
+
{"type":"module","version":"10.30.0","sideEffects":false}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { browserTracingIntegration, WINDOW, startBrowserTracingPageLoadSpan, startBrowserTracingNavigationSpan } from '@sentry/browser';
|
|
2
|
-
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, debug, spanToJSON,
|
|
2
|
+
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, debug, spanToJSON, getCurrentScope, getClient, addNonEnumerableProperty } from '@sentry/core';
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { DEBUG_BUILD } from '../debug-build.js';
|
|
5
5
|
import { hoistNonReactStatics } from '../hoist-non-react-statics.js';
|
|
6
6
|
import { checkRouteForAsyncHandler } from './lazy-routes.js';
|
|
7
|
-
import { resolveRouteNameAndSource, transactionNameHasWildcard, initializeRouterUtils } from './utils.js';
|
|
7
|
+
import { getActiveRootSpan, setNavigationContext, clearNavigationContext, resolveRouteNameAndSource, transactionNameHasWildcard, initializeRouterUtils } from './utils.js';
|
|
8
8
|
|
|
9
9
|
/* eslint-disable max-lines */
|
|
10
10
|
// Inspired from Donnie McNeal's solution:
|
|
@@ -160,11 +160,14 @@ function trackLazyRouteLoad(span, promise) {
|
|
|
160
160
|
|
|
161
161
|
/**
|
|
162
162
|
* Processes resolved routes by adding them to allRoutes and checking for nested async handlers.
|
|
163
|
+
* When capturedSpan is provided, updates that specific span instead of the current active span.
|
|
164
|
+
* This prevents race conditions where a lazy handler resolves after the user has navigated away.
|
|
163
165
|
*/
|
|
164
166
|
function processResolvedRoutes(
|
|
165
167
|
resolvedRoutes,
|
|
166
168
|
parentRoute,
|
|
167
169
|
currentLocation = null,
|
|
170
|
+
capturedSpan,
|
|
168
171
|
) {
|
|
169
172
|
resolvedRoutes.forEach(child => {
|
|
170
173
|
allRoutes.add(child);
|
|
@@ -179,17 +182,27 @@ function processResolvedRoutes(
|
|
|
179
182
|
addResolvedRoutesToParent(resolvedRoutes, parentRoute);
|
|
180
183
|
}
|
|
181
184
|
|
|
182
|
-
//
|
|
183
|
-
const
|
|
184
|
-
if (
|
|
185
|
-
const
|
|
185
|
+
// Use captured span if provided, otherwise fall back to current active span
|
|
186
|
+
const targetSpan = capturedSpan ?? getActiveRootSpan();
|
|
187
|
+
if (targetSpan) {
|
|
188
|
+
const spanJson = spanToJSON(targetSpan);
|
|
189
|
+
|
|
190
|
+
// Skip update if span has already ended (timestamp is set when span.end() is called)
|
|
191
|
+
if (spanJson.timestamp) {
|
|
192
|
+
DEBUG_BUILD && debug.warn('[React Router] Lazy handler resolved after span ended - skipping update');
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const spanOp = spanJson.op;
|
|
186
197
|
|
|
187
|
-
//
|
|
198
|
+
// Use captured location for route matching (ensures we match against the correct route)
|
|
199
|
+
// Fall back to window.location only if no captured location and no captured span
|
|
200
|
+
// (i.e., this is not from an async handler)
|
|
188
201
|
let location = currentLocation;
|
|
189
|
-
if (!location) {
|
|
202
|
+
if (!location && !capturedSpan) {
|
|
190
203
|
if (typeof WINDOW !== 'undefined') {
|
|
191
204
|
const globalLocation = WINDOW.location;
|
|
192
|
-
if (globalLocation) {
|
|
205
|
+
if (globalLocation?.pathname) {
|
|
193
206
|
location = { pathname: globalLocation.pathname };
|
|
194
207
|
}
|
|
195
208
|
}
|
|
@@ -199,14 +212,14 @@ function processResolvedRoutes(
|
|
|
199
212
|
if (spanOp === 'pageload') {
|
|
200
213
|
// Re-run the pageload transaction update with the newly loaded routes
|
|
201
214
|
updatePageloadTransaction({
|
|
202
|
-
activeRootSpan,
|
|
215
|
+
activeRootSpan: targetSpan,
|
|
203
216
|
location: { pathname: location.pathname },
|
|
204
217
|
routes: Array.from(allRoutes),
|
|
205
218
|
allRoutes: Array.from(allRoutes),
|
|
206
219
|
});
|
|
207
220
|
} else if (spanOp === 'navigation') {
|
|
208
221
|
// For navigation spans, update the name with the newly loaded routes
|
|
209
|
-
updateNavigationSpan(
|
|
222
|
+
updateNavigationSpan(targetSpan, location, Array.from(allRoutes), false, _matchRoutes);
|
|
210
223
|
}
|
|
211
224
|
}
|
|
212
225
|
}
|
|
@@ -637,7 +650,12 @@ function wrapPatchRoutesOnNavigation(
|
|
|
637
650
|
(args ).patch = (routeId, children) => {
|
|
638
651
|
addRoutesToAllRoutes(children);
|
|
639
652
|
const currentActiveRootSpan = getActiveRootSpan();
|
|
640
|
-
if
|
|
653
|
+
// Only update if we have a valid targetPath (patchRoutesOnNavigation can be called without path)
|
|
654
|
+
if (
|
|
655
|
+
targetPath &&
|
|
656
|
+
currentActiveRootSpan &&
|
|
657
|
+
(spanToJSON(currentActiveRootSpan) ).op === 'navigation'
|
|
658
|
+
) {
|
|
641
659
|
updateNavigationSpan(
|
|
642
660
|
currentActiveRootSpan,
|
|
643
661
|
{ pathname: targetPath, search: '', hash: '', state: null, key: 'default' },
|
|
@@ -652,7 +670,14 @@ function wrapPatchRoutesOnNavigation(
|
|
|
652
670
|
}
|
|
653
671
|
|
|
654
672
|
const lazyLoadPromise = (async () => {
|
|
655
|
-
|
|
673
|
+
// Set context so async handlers can access correct targetPath and span
|
|
674
|
+
const contextToken = setNavigationContext(targetPath, activeRootSpan);
|
|
675
|
+
let result;
|
|
676
|
+
try {
|
|
677
|
+
result = await originalPatchRoutes(args);
|
|
678
|
+
} finally {
|
|
679
|
+
clearNavigationContext(contextToken);
|
|
680
|
+
}
|
|
656
681
|
|
|
657
682
|
const currentActiveRootSpan = getActiveRootSpan();
|
|
658
683
|
if (currentActiveRootSpan && (spanToJSON(currentActiveRootSpan) ).op === 'navigation') {
|
|
@@ -1098,19 +1123,5 @@ function createV6CompatibleWithSentryReactRouterRouting(
|
|
|
1098
1123
|
return SentryRoutes;
|
|
1099
1124
|
}
|
|
1100
1125
|
|
|
1101
|
-
function getActiveRootSpan() {
|
|
1102
|
-
const span = getActiveSpan();
|
|
1103
|
-
const rootSpan = span ? getRootSpan(span) : undefined;
|
|
1104
|
-
|
|
1105
|
-
if (!rootSpan) {
|
|
1106
|
-
return undefined;
|
|
1107
|
-
}
|
|
1108
|
-
|
|
1109
|
-
const op = spanToJSON(rootSpan).op;
|
|
1110
|
-
|
|
1111
|
-
// Only use this root span if it is a pageload or navigation span
|
|
1112
|
-
return op === 'navigation' || op === 'pageload' ? rootSpan : undefined;
|
|
1113
|
-
}
|
|
1114
|
-
|
|
1115
1126
|
export { addResolvedRoutesToParent, addRoutesToAllRoutes, allRoutes, computeLocationKey, createReactRouterV6CompatibleTracingIntegration, createV6CompatibleWithSentryReactRouterRouting, createV6CompatibleWrapCreateBrowserRouter, createV6CompatibleWrapCreateMemoryRouter, createV6CompatibleWrapUseRoutes, handleNavigation, processResolvedRoutes, shouldSkipNavigation, updateNavigationSpan };
|
|
1116
1127
|
//# sourceMappingURL=instrumentation.js.map
|