@sentry/react 10.38.0 → 10.39.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 +26 -2
- package/build/cjs/reactrouter-compat-utils/instrumentation.js.map +1 -1
- package/build/cjs/reactrouter-compat-utils/route-manifest.js +194 -0
- package/build/cjs/reactrouter-compat-utils/route-manifest.js.map +1 -0
- package/build/cjs/reactrouter-compat-utils/utils.js +16 -31
- package/build/cjs/reactrouter-compat-utils/utils.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/reactrouter-compat-utils/instrumentation.js +26 -2
- package/build/esm/reactrouter-compat-utils/instrumentation.js.map +1 -1
- package/build/esm/reactrouter-compat-utils/route-manifest.js +191 -0
- package/build/esm/reactrouter-compat-utils/route-manifest.js.map +1 -0
- package/build/esm/reactrouter-compat-utils/utils.js +12 -27
- package/build/esm/reactrouter-compat-utils/utils.js.map +1 -1
- package/build/types/reactrouter-compat-utils/instrumentation.d.ts +18 -0
- package/build/types/reactrouter-compat-utils/instrumentation.d.ts.map +1 -1
- package/build/types/reactrouter-compat-utils/route-manifest.d.ts +13 -0
- package/build/types/reactrouter-compat-utils/route-manifest.d.ts.map +1 -0
- package/build/types/reactrouter-compat-utils/utils.d.ts +1 -1
- package/build/types/reactrouter-compat-utils/utils.d.ts.map +1 -1
- package/build/types-ts3.8/reactrouter-compat-utils/instrumentation.d.ts +18 -0
- package/build/types-ts3.8/reactrouter-compat-utils/route-manifest.d.ts +13 -0
- package/build/types-ts3.8/reactrouter-compat-utils/utils.d.ts +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
const core = require('@sentry/core');
|
|
4
|
+
const debugBuild = require('../debug-build.js');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Strip the basename from a pathname if exists.
|
|
8
|
+
*
|
|
9
|
+
* Vendored and modified from `react-router`
|
|
10
|
+
* https://github.com/remix-run/react-router/blob/462bb712156a3f739d6139a0f14810b76b002df6/packages/router/utils.ts#L1038
|
|
11
|
+
*/
|
|
12
|
+
function stripBasenameFromPathname(pathname, basename) {
|
|
13
|
+
if (!basename || basename === '/') {
|
|
14
|
+
return pathname;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (!pathname.toLowerCase().startsWith(basename.toLowerCase())) {
|
|
18
|
+
return pathname;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// We want to leave trailing slash behavior in the user's control, so if they
|
|
22
|
+
// specify a basename with a trailing slash, we should support it
|
|
23
|
+
const startIndex = basename.endsWith('/') ? basename.length - 1 : basename.length;
|
|
24
|
+
const nextChar = pathname.charAt(startIndex);
|
|
25
|
+
if (nextChar && nextChar !== '/') {
|
|
26
|
+
// pathname does not start with basename/
|
|
27
|
+
return pathname;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return pathname.slice(startIndex) || '/';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Cache for sorted manifests - keyed by manifest array reference
|
|
34
|
+
const SORTED_MANIFEST_CACHE = new WeakMap();
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Matches a pathname against a route manifest and returns the matching pattern.
|
|
38
|
+
* Optionally strips a basename prefix before matching.
|
|
39
|
+
*/
|
|
40
|
+
function matchRouteManifest(pathname, manifest, basename) {
|
|
41
|
+
if (!pathname || !manifest || !manifest.length) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const normalizedPathname = basename ? stripBasenameFromPathname(pathname, basename) : pathname;
|
|
46
|
+
|
|
47
|
+
let sorted = SORTED_MANIFEST_CACHE.get(manifest);
|
|
48
|
+
if (!sorted) {
|
|
49
|
+
sorted = sortBySpecificity(manifest);
|
|
50
|
+
SORTED_MANIFEST_CACHE.set(manifest, sorted);
|
|
51
|
+
debugBuild.DEBUG_BUILD && core.debug.log('[React Router] Sorted route manifest by specificity:', sorted.length, 'patterns');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
for (const pattern of sorted) {
|
|
55
|
+
if (matchesPattern(normalizedPathname, pattern)) {
|
|
56
|
+
debugBuild.DEBUG_BUILD && core.debug.log('[React Router] Matched pathname', normalizedPathname, 'to pattern', pattern);
|
|
57
|
+
return pattern;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
debugBuild.DEBUG_BUILD && core.debug.log('[React Router] No manifest match found for pathname:', normalizedPathname);
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Checks if a pathname matches a route pattern.
|
|
67
|
+
*/
|
|
68
|
+
function matchesPattern(pathname, pattern) {
|
|
69
|
+
// Handle root path special case
|
|
70
|
+
if (pattern === '/') {
|
|
71
|
+
return pathname === '/' || pathname === '';
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const pathSegments = splitPath(pathname);
|
|
75
|
+
const patternSegments = splitPath(pattern);
|
|
76
|
+
|
|
77
|
+
// Handle wildcard at end
|
|
78
|
+
const hasWildcard = patternSegments.length > 0 && patternSegments[patternSegments.length - 1] === '*';
|
|
79
|
+
|
|
80
|
+
if (hasWildcard) {
|
|
81
|
+
// Pattern with wildcard: path must have at least as many segments as pattern (minus wildcard)
|
|
82
|
+
const patternSegmentsWithoutWildcard = patternSegments.slice(0, -1);
|
|
83
|
+
if (pathSegments.length < patternSegmentsWithoutWildcard.length) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
for (const [i, patternSegment] of patternSegmentsWithoutWildcard.entries()) {
|
|
87
|
+
if (!segmentMatches(pathSegments[i], patternSegment)) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Exact segment count match required
|
|
95
|
+
if (pathSegments.length !== patternSegments.length) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
for (const [i, patternSegment] of patternSegments.entries()) {
|
|
100
|
+
if (!segmentMatches(pathSegments[i], patternSegment)) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Checks if a path segment matches a pattern segment.
|
|
110
|
+
*/
|
|
111
|
+
function segmentMatches(pathSegment, patternSegment) {
|
|
112
|
+
if (pathSegment === undefined || patternSegment === undefined) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
// Parameter matches anything
|
|
116
|
+
if (PARAM_RE.test(patternSegment)) {
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
// Literal must match exactly
|
|
120
|
+
return pathSegment === patternSegment;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Splits a path into segments, filtering out empty strings.
|
|
125
|
+
*/
|
|
126
|
+
function splitPath(path) {
|
|
127
|
+
return path.split('/').filter(Boolean);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* React Router scoring weights and param detection.
|
|
132
|
+
* https://github.com/remix-run/react-router/blob/main/packages/react-router/lib/router/utils.ts
|
|
133
|
+
*/
|
|
134
|
+
const PARAM_RE = /^:[\w-]+$/;
|
|
135
|
+
const STATIC_SEGMENT_SCORE = 10;
|
|
136
|
+
const DYNAMIC_SEGMENT_SCORE = 3;
|
|
137
|
+
const EMPTY_SEGMENT_SCORE = 1;
|
|
138
|
+
const SPLAT_PENALTY = -2;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Computes a specificity score for a route pattern.
|
|
142
|
+
* Matches React Router's computeScore() algorithm exactly.
|
|
143
|
+
*/
|
|
144
|
+
function computeScore(pattern) {
|
|
145
|
+
const segments = pattern.split('/');
|
|
146
|
+
|
|
147
|
+
// Base score is segment count (including empty segment from leading slash)
|
|
148
|
+
let score = segments.length;
|
|
149
|
+
|
|
150
|
+
// Apply splat penalty once if pattern contains wildcard
|
|
151
|
+
if (segments.includes('*')) {
|
|
152
|
+
score += SPLAT_PENALTY;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
for (const segment of segments) {
|
|
156
|
+
if (segment === '*') {
|
|
157
|
+
// Splat penalty already applied globally above
|
|
158
|
+
continue;
|
|
159
|
+
} else if (PARAM_RE.test(segment)) {
|
|
160
|
+
score += DYNAMIC_SEGMENT_SCORE;
|
|
161
|
+
} else if (segment === '') {
|
|
162
|
+
score += EMPTY_SEGMENT_SCORE;
|
|
163
|
+
} else {
|
|
164
|
+
score += STATIC_SEGMENT_SCORE;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return score;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Sorts route patterns by specificity (most specific first).
|
|
173
|
+
* Implements React Router's ranking algorithm from computeScore():
|
|
174
|
+
* https://github.com/remix-run/react-router/blob/main/packages/react-router/lib/router/utils.ts
|
|
175
|
+
*
|
|
176
|
+
* React Router scoring: base=segments.length, static=+10, dynamic=+3, empty=+1, splat=-2 (once)
|
|
177
|
+
* Higher score = more specific pattern.
|
|
178
|
+
* Equal scores preserve manifest order (same as React Router).
|
|
179
|
+
*
|
|
180
|
+
* Note: Users should order their manifest from most specific to least specific
|
|
181
|
+
* when patterns have equal specificity (e.g., `/users/:id/settings` and `/:type/123/settings`).
|
|
182
|
+
*/
|
|
183
|
+
function sortBySpecificity(manifest) {
|
|
184
|
+
return [...manifest].sort((a, b) => {
|
|
185
|
+
const aScore = computeScore(a);
|
|
186
|
+
const bScore = computeScore(b);
|
|
187
|
+
|
|
188
|
+
return bScore - aScore;
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
exports.matchRouteManifest = matchRouteManifest;
|
|
193
|
+
exports.stripBasenameFromPathname = stripBasenameFromPathname;
|
|
194
|
+
//# sourceMappingURL=route-manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-manifest.js","sources":["../../../src/reactrouter-compat-utils/route-manifest.ts"],"sourcesContent":["import { debug } from '@sentry/core';\nimport { DEBUG_BUILD } from '../debug-build';\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 */\nexport function 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// Cache for sorted manifests - keyed by manifest array reference\nconst SORTED_MANIFEST_CACHE = new WeakMap<string[], string[]>();\n\n/**\n * Matches a pathname against a route manifest and returns the matching pattern.\n * Optionally strips a basename prefix before matching.\n */\nexport function matchRouteManifest(pathname: string, manifest: string[], basename?: string): string | null {\n if (!pathname || !manifest || !manifest.length) {\n return null;\n }\n\n const normalizedPathname = basename ? stripBasenameFromPathname(pathname, basename) : pathname;\n\n let sorted = SORTED_MANIFEST_CACHE.get(manifest);\n if (!sorted) {\n sorted = sortBySpecificity(manifest);\n SORTED_MANIFEST_CACHE.set(manifest, sorted);\n DEBUG_BUILD && debug.log('[React Router] Sorted route manifest by specificity:', sorted.length, 'patterns');\n }\n\n for (const pattern of sorted) {\n if (matchesPattern(normalizedPathname, pattern)) {\n DEBUG_BUILD && debug.log('[React Router] Matched pathname', normalizedPathname, 'to pattern', pattern);\n return pattern;\n }\n }\n\n DEBUG_BUILD && debug.log('[React Router] No manifest match found for pathname:', normalizedPathname);\n return null;\n}\n\n/**\n * Checks if a pathname matches a route pattern.\n */\nfunction matchesPattern(pathname: string, pattern: string): boolean {\n // Handle root path special case\n if (pattern === '/') {\n return pathname === '/' || pathname === '';\n }\n\n const pathSegments = splitPath(pathname);\n const patternSegments = splitPath(pattern);\n\n // Handle wildcard at end\n const hasWildcard = patternSegments.length > 0 && patternSegments[patternSegments.length - 1] === '*';\n\n if (hasWildcard) {\n // Pattern with wildcard: path must have at least as many segments as pattern (minus wildcard)\n const patternSegmentsWithoutWildcard = patternSegments.slice(0, -1);\n if (pathSegments.length < patternSegmentsWithoutWildcard.length) {\n return false;\n }\n for (const [i, patternSegment] of patternSegmentsWithoutWildcard.entries()) {\n if (!segmentMatches(pathSegments[i], patternSegment)) {\n return false;\n }\n }\n return true;\n }\n\n // Exact segment count match required\n if (pathSegments.length !== patternSegments.length) {\n return false;\n }\n\n for (const [i, patternSegment] of patternSegments.entries()) {\n if (!segmentMatches(pathSegments[i], patternSegment)) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Checks if a path segment matches a pattern segment.\n */\nfunction segmentMatches(pathSegment: string | undefined, patternSegment: string | undefined): boolean {\n if (pathSegment === undefined || patternSegment === undefined) {\n return false;\n }\n // Parameter matches anything\n if (PARAM_RE.test(patternSegment)) {\n return true;\n }\n // Literal must match exactly\n return pathSegment === patternSegment;\n}\n\n/**\n * Splits a path into segments, filtering out empty strings.\n */\nfunction splitPath(path: string): string[] {\n return path.split('/').filter(Boolean);\n}\n\n/**\n * React Router scoring weights and param detection.\n * https://github.com/remix-run/react-router/blob/main/packages/react-router/lib/router/utils.ts\n */\nconst PARAM_RE = /^:[\\w-]+$/;\nconst STATIC_SEGMENT_SCORE = 10;\nconst DYNAMIC_SEGMENT_SCORE = 3;\nconst EMPTY_SEGMENT_SCORE = 1;\nconst SPLAT_PENALTY = -2;\n\n/**\n * Computes a specificity score for a route pattern.\n * Matches React Router's computeScore() algorithm exactly.\n */\nfunction computeScore(pattern: string): number {\n const segments = pattern.split('/');\n\n // Base score is segment count (including empty segment from leading slash)\n let score = segments.length;\n\n // Apply splat penalty once if pattern contains wildcard\n if (segments.includes('*')) {\n score += SPLAT_PENALTY;\n }\n\n for (const segment of segments) {\n if (segment === '*') {\n // Splat penalty already applied globally above\n continue;\n } else if (PARAM_RE.test(segment)) {\n score += DYNAMIC_SEGMENT_SCORE;\n } else if (segment === '') {\n score += EMPTY_SEGMENT_SCORE;\n } else {\n score += STATIC_SEGMENT_SCORE;\n }\n }\n\n return score;\n}\n\n/**\n * Sorts route patterns by specificity (most specific first).\n * Implements React Router's ranking algorithm from computeScore():\n * https://github.com/remix-run/react-router/blob/main/packages/react-router/lib/router/utils.ts\n *\n * React Router scoring: base=segments.length, static=+10, dynamic=+3, empty=+1, splat=-2 (once)\n * Higher score = more specific pattern.\n * Equal scores preserve manifest order (same as React Router).\n *\n * Note: Users should order their manifest from most specific to least specific\n * when patterns have equal specificity (e.g., `/users/:id/settings` and `/:type/123/settings`).\n */\nfunction sortBySpecificity(manifest: string[]): string[] {\n return [...manifest].sort((a, b) => {\n const aScore = computeScore(a);\n const bScore = computeScore(b);\n\n return bScore - aScore;\n });\n}\n"],"names":["DEBUG_BUILD","debug"],"mappings":";;;;;AAGA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,yBAAyB,CAAC,QAAQ,EAAU,QAAQ,EAAkB;AACtF,EAAE,IAAI,CAAC,QAAA,IAAY,QAAA,KAAa,GAAG,EAAE;AACrC,IAAI,OAAO,QAAQ;AACnB,EAAE;;AAEF,EAAE,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,EAAE;AAClE,IAAI,OAAO,QAAQ;AACnB,EAAE;;AAEF;AACA;AACA,EAAE,MAAM,UAAA,GAAa,QAAQ,CAAC,QAAQ,CAAC,GAAG,CA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,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE;AACvC,MAAM,KAAA,IAAS,qBAAqB;AACpC,IAAI,OAAO,IAAI,OAAA,KAAY,EAAE,EAAE;AAC/B,MAAM,KAAA,IAAS,mBAAmB;AAClC,IAAI,OAAO;AACX,MAAM,KAAA,IAAS,oBAAoB;AACnC,IAAI;AACJ,EAAE;;AAEF,EAAE,OAAO,KAAK;AACd;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,iBAAiB,CAAC,QAAQ,EAAsB;AACzD,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK;AACtC,IAAI,MAAM,MAAA,GAAS,YAAY,CAAC,CAAC,CAAC;AAClC,IAAI,MAAM,MAAA,GAAS,YAAY,CAAC,CAAC,CAAC;;AAElC,IAAI,OAAO,MAAA,GAAS,MAAM;AAC1B,EAAE,CAAC,CAAC;AACJ;;;;;"}
|
|
@@ -2,6 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
|
|
3
3
|
const core = require('@sentry/core');
|
|
4
4
|
const debugBuild = require('../debug-build.js');
|
|
5
|
+
const routeManifest = require('./route-manifest.js');
|
|
5
6
|
|
|
6
7
|
// Global variables that these utilities depend on
|
|
7
8
|
let _matchRoutes;
|
|
@@ -102,7 +103,7 @@ function sendIndexPath(pathBuilder, pathname, basename) {
|
|
|
102
103
|
pathBuilder && pathBuilder.length > 0
|
|
103
104
|
? pathBuilder
|
|
104
105
|
: _stripBasename
|
|
105
|
-
? stripBasenameFromPathname(pathname, basename)
|
|
106
|
+
? routeManifest.stripBasenameFromPathname(pathname, basename)
|
|
106
107
|
: pathname;
|
|
107
108
|
|
|
108
109
|
let formattedPath =
|
|
@@ -129,33 +130,6 @@ function getNumberOfUrlSegments(url) {
|
|
|
129
130
|
return url.split(/\\?\//).filter(s => s.length > 0 && s !== ',').length;
|
|
130
131
|
}
|
|
131
132
|
|
|
132
|
-
/**
|
|
133
|
-
* Strip the basename from a pathname if exists.
|
|
134
|
-
*
|
|
135
|
-
* Vendored and modified from `react-router`
|
|
136
|
-
* https://github.com/remix-run/react-router/blob/462bb712156a3f739d6139a0f14810b76b002df6/packages/router/utils.ts#L1038
|
|
137
|
-
*/
|
|
138
|
-
function stripBasenameFromPathname(pathname, basename) {
|
|
139
|
-
if (!basename || basename === '/') {
|
|
140
|
-
return pathname;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if (!pathname.toLowerCase().startsWith(basename.toLowerCase())) {
|
|
144
|
-
return pathname;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// We want to leave trailing slash behavior in the user's control, so if they
|
|
148
|
-
// specify a basename with a trailing slash, we should support it
|
|
149
|
-
const startIndex = basename.endsWith('/') ? basename.length - 1 : basename.length;
|
|
150
|
-
const nextChar = pathname.charAt(startIndex);
|
|
151
|
-
if (nextChar && nextChar !== '/') {
|
|
152
|
-
// pathname does not start with basename/
|
|
153
|
-
return pathname;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
return pathname.slice(startIndex) || '/';
|
|
157
|
-
}
|
|
158
|
-
|
|
159
133
|
// Exported utility functions
|
|
160
134
|
|
|
161
135
|
/**
|
|
@@ -178,7 +152,7 @@ function rebuildRoutePathFromAllRoutes(allRoutes, location) {
|
|
|
178
152
|
for (const match of matchedRoutes) {
|
|
179
153
|
if (match.route.path && match.route.path !== '*') {
|
|
180
154
|
const path = pickPath(match);
|
|
181
|
-
const strippedPath = stripBasenameFromPathname(location.pathname, prefixWithSlash(match.pathnameBase));
|
|
155
|
+
const strippedPath = routeManifest.stripBasenameFromPathname(location.pathname, prefixWithSlash(match.pathnameBase));
|
|
182
156
|
|
|
183
157
|
if (location.pathname === strippedPath) {
|
|
184
158
|
return trimSlash(strippedPath);
|
|
@@ -222,7 +196,7 @@ function locationIsInsideDescendantRoute(location, routes) {
|
|
|
222
196
|
* Returns a fallback transaction name from location pathname.
|
|
223
197
|
*/
|
|
224
198
|
function getFallbackTransactionName(location, basename) {
|
|
225
|
-
return _stripBasename ? stripBasenameFromPathname(location.pathname, basename) : location.pathname || '';
|
|
199
|
+
return _stripBasename ? routeManifest.stripBasenameFromPathname(location.pathname, basename) : location.pathname || '';
|
|
226
200
|
}
|
|
227
201
|
|
|
228
202
|
/**
|
|
@@ -235,7 +209,7 @@ function getNormalizedName(
|
|
|
235
209
|
basename = '',
|
|
236
210
|
) {
|
|
237
211
|
if (!routes || routes.length === 0) {
|
|
238
|
-
return [_stripBasename ? stripBasenameFromPathname(location.pathname, basename) : location.pathname, 'url'];
|
|
212
|
+
return [_stripBasename ? routeManifest.stripBasenameFromPathname(location.pathname, basename) : location.pathname, 'url'];
|
|
239
213
|
}
|
|
240
214
|
|
|
241
215
|
if (!branches) {
|
|
@@ -298,7 +272,18 @@ function resolveRouteNameAndSource(
|
|
|
298
272
|
allRoutes,
|
|
299
273
|
branches,
|
|
300
274
|
basename = '',
|
|
275
|
+
lazyRouteManifest,
|
|
276
|
+
enableAsyncRouteHandlers,
|
|
301
277
|
) {
|
|
278
|
+
// When lazy route manifest is provided, use it as the primary source for transaction names
|
|
279
|
+
if (enableAsyncRouteHandlers && lazyRouteManifest && lazyRouteManifest.length > 0) {
|
|
280
|
+
const manifestMatch = routeManifest.matchRouteManifest(location.pathname, lazyRouteManifest, basename);
|
|
281
|
+
if (manifestMatch) {
|
|
282
|
+
return [(_stripBasename ? '' : basename) + manifestMatch, 'route'];
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// Fall back to React Router route matching
|
|
302
287
|
let name;
|
|
303
288
|
let source = 'url';
|
|
304
289
|
|
|
@@ -1 +1 @@
|
|
|
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,uBAAu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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;;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;;;;;;;;;;;;;;;;;;"}
|
|
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';\nimport { matchRouteManifest, stripBasenameFromPathname } from './route-manifest';\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// 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 lazyRouteManifest?: string[],\n enableAsyncRouteHandlers?: boolean,\n): [string, TransactionSource] {\n // When lazy route manifest is provided, use it as the primary source for transaction names\n if (enableAsyncRouteHandlers && lazyRouteManifest && lazyRouteManifest.length > 0) {\n const manifestMatch = matchRouteManifest(location.pathname, lazyRouteManifest, basename);\n if (manifestMatch) {\n return [(_stripBasename ? '' : basename) + manifestMatch, 'route'];\n }\n }\n\n // Fall back to React Router route matching\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","stripBasenameFromPathname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A,aAAA,EAAA;AACA,MAAA,OAAA,CAAA,CAAA,cAAA,GAAA,EAAA,GAAA,QAAA,IAAA,aAAA,EAAA,OAAA,CAAA;AACA,IAAA;AACA,EAAA;;AAEA;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;;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;;;;;;;;;;;;;;;;;;"}
|
package/build/esm/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"type":"module","version":"10.
|
|
1
|
+
{"type":"module","version":"10.39.0","sideEffects":false}
|
|
@@ -19,6 +19,8 @@ let _matchRoutes;
|
|
|
19
19
|
|
|
20
20
|
let _enableAsyncRouteHandlers = false;
|
|
21
21
|
let _lazyRouteTimeout = 3000;
|
|
22
|
+
let _lazyRouteManifest;
|
|
23
|
+
let _basename = '';
|
|
22
24
|
|
|
23
25
|
const CLIENTS_WITH_INSTRUMENT_NAVIGATION = new WeakSet();
|
|
24
26
|
|
|
@@ -280,7 +282,9 @@ function updateNavigationSpan(
|
|
|
280
282
|
allRoutes,
|
|
281
283
|
allRoutes,
|
|
282
284
|
(currentBranches ) || [],
|
|
283
|
-
|
|
285
|
+
_basename,
|
|
286
|
+
_lazyRouteManifest,
|
|
287
|
+
_enableAsyncRouteHandlers,
|
|
284
288
|
);
|
|
285
289
|
|
|
286
290
|
const currentSource = spanJson.data?.[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE];
|
|
@@ -444,6 +448,9 @@ function createV6CompatibleWrapCreateBrowserRouter
|
|
|
444
448
|
});
|
|
445
449
|
}
|
|
446
450
|
|
|
451
|
+
// Store basename for use in updateNavigationSpan
|
|
452
|
+
_basename = basename || '';
|
|
453
|
+
|
|
447
454
|
setupRouterSubscription(router, routes, version, basename, activeRootSpan);
|
|
448
455
|
|
|
449
456
|
return router;
|
|
@@ -535,6 +542,9 @@ function createV6CompatibleWrapCreateMemoryRouter
|
|
|
535
542
|
});
|
|
536
543
|
}
|
|
537
544
|
|
|
545
|
+
// Store basename for use in updateNavigationSpan
|
|
546
|
+
_basename = basename || '';
|
|
547
|
+
|
|
538
548
|
setupRouterSubscription(router, routes, version, basename, memoryActiveRootSpan);
|
|
539
549
|
|
|
540
550
|
return router;
|
|
@@ -561,6 +571,7 @@ function createReactRouterV6CompatibleTracingIntegration(
|
|
|
561
571
|
instrumentPageLoad = true,
|
|
562
572
|
instrumentNavigation = true,
|
|
563
573
|
lazyRouteTimeout,
|
|
574
|
+
lazyRouteManifest,
|
|
564
575
|
} = options;
|
|
565
576
|
|
|
566
577
|
return {
|
|
@@ -604,6 +615,7 @@ function createReactRouterV6CompatibleTracingIntegration(
|
|
|
604
615
|
_matchRoutes = matchRoutes;
|
|
605
616
|
_createRoutesFromChildren = createRoutesFromChildren;
|
|
606
617
|
_enableAsyncRouteHandlers = enableAsyncRouteHandlers;
|
|
618
|
+
_lazyRouteManifest = lazyRouteManifest;
|
|
607
619
|
|
|
608
620
|
// Initialize the router utils with the required dependencies
|
|
609
621
|
initializeRouterUtils(matchRoutes, stripBasename || false);
|
|
@@ -845,6 +857,8 @@ function handleNavigation(opts
|
|
|
845
857
|
allRoutes || routes,
|
|
846
858
|
branches ,
|
|
847
859
|
basename,
|
|
860
|
+
_lazyRouteManifest,
|
|
861
|
+
_enableAsyncRouteHandlers,
|
|
848
862
|
);
|
|
849
863
|
|
|
850
864
|
const locationKey = computeLocationKey(location);
|
|
@@ -979,6 +993,8 @@ function updatePageloadTransaction({
|
|
|
979
993
|
allRoutes || routes,
|
|
980
994
|
branches,
|
|
981
995
|
basename,
|
|
996
|
+
_lazyRouteManifest,
|
|
997
|
+
_enableAsyncRouteHandlers,
|
|
982
998
|
);
|
|
983
999
|
|
|
984
1000
|
getCurrentScope().setTransactionName(name || '/');
|
|
@@ -1066,7 +1082,15 @@ function tryUpdateSpanNameBeforeEnd(
|
|
|
1066
1082
|
return;
|
|
1067
1083
|
}
|
|
1068
1084
|
|
|
1069
|
-
const [name, source] = resolveRouteNameAndSource(
|
|
1085
|
+
const [name, source] = resolveRouteNameAndSource(
|
|
1086
|
+
location,
|
|
1087
|
+
routesToUse,
|
|
1088
|
+
routesToUse,
|
|
1089
|
+
branches,
|
|
1090
|
+
basename,
|
|
1091
|
+
_lazyRouteManifest,
|
|
1092
|
+
_enableAsyncRouteHandlers,
|
|
1093
|
+
);
|
|
1070
1094
|
|
|
1071
1095
|
const isImprovement = shouldUpdateWildcardSpanName(currentName, currentSource, name, source, true);
|
|
1072
1096
|
const spanNotEnded = spanType === 'pageload' || !spanJson.timestamp;
|