@@ -98,6 +98,7 @@ export function reactRouterV6BrowserTracingIntegration(
98
98
integration . afterAllSetup ( client ) ;
99
99
100
100
const initPathName = WINDOW && WINDOW . location && WINDOW . location . pathname ;
101
+
101
102
if ( instrumentPageLoad && initPathName ) {
102
103
startBrowserTracingPageLoadSpan ( client , {
103
104
name : initPathName ,
@@ -158,16 +159,16 @@ function sendIndexPath(pathBuilder: string, pathname: string, basename: string):
158
159
return [ formattedPath , 'route' ] ;
159
160
}
160
161
161
- function pathEndsWithWildcard ( path : string ) : boolean {
162
- return path . endsWith ( '*' ) ;
162
+ function matchHasWildcard ( match : RouteMatch < string > ) : boolean {
163
+ return ! ! match . params [ '*' ] ;
163
164
}
164
165
165
- function pathIsWildcardAndHasChildren ( path : string , branch : RouteMatch < string > ) : boolean {
166
- return ( pathEndsWithWildcard ( path ) && branch . route . children && branch . route . children . length > 0 ) || false ;
166
+ function pathEndsWithWildcard ( path : string ) : boolean {
167
+ return path . endsWith ( '*' ) ;
167
168
}
168
169
169
- function pathIsWildcardWithNoChildren ( path : string , branch : RouteMatch < string > ) : boolean {
170
- return ( pathEndsWithWildcard ( path ) && ( ! branch . route . children || branch . route . children . length === 0 ) ) || false ;
170
+ function matchIsWildcardAndHasChildren ( path : string , match : RouteMatch < string > ) : boolean {
171
+ return ( matchHasWildcard ( match ) && match . route . children && match . route . children . length > 0 ) || false ;
171
172
}
172
173
173
174
function getNormalizedName (
@@ -178,24 +179,31 @@ function getNormalizedName(
178
179
allRoutes : RouteObject [ ] = routes ,
179
180
) : [ string , TransactionSource ] {
180
181
if ( ! routes || routes . length === 0 ) {
182
+ debugger ;
181
183
return [ _stripBasename ? stripBasenameFromPathname ( location . pathname , basename ) : location . pathname , 'url' ] ;
182
184
}
183
185
184
- const matchedRoutes = _matchRoutes ( routes , location ) ;
186
+ const matchedRoutes = _matchRoutes ( allRoutes , location , basename ) ;
185
187
186
188
if ( matchedRoutes ) {
187
- const wildCardRoutes : RouteMatch [ ] = matchedRoutes . filter (
188
- ( match : RouteMatch ) => match . route . path && pathIsWildcardWithNoChildren ( match . route . path , match ) ,
189
- ) ;
189
+ const wildCardRoutes : RouteMatch [ ] = matchedRoutes . filter ( ( match : RouteMatch ) => {
190
+ return matchHasWildcard ( match ) ;
191
+ } ) ;
190
192
191
193
for ( const wildCardRoute of wildCardRoutes ) {
192
194
const wildCardRouteMatch = _matchRoutes ( allRoutes , location , wildCardRoute . pathnameBase ) ;
193
195
194
196
if ( wildCardRouteMatch ) {
195
- const [ name , source ] = getNormalizedName ( wildCardRoutes , location , wildCardRouteMatch , basename , allRoutes ) ;
197
+ const [ name , source ] = getNormalizedName (
198
+ wildCardRoutes ,
199
+ location ,
200
+ wildCardRouteMatch ,
201
+ wildCardRoute . pathnameBase ,
202
+ allRoutes ,
203
+ ) ;
196
204
197
205
if ( wildCardRoute . pathnameBase && name ) {
198
- return [ wildCardRoute . pathnameBase + name , source ] ;
206
+ return [ basename + wildCardRoute . pathnameBase + name , source ] ;
199
207
}
200
208
}
201
209
}
@@ -208,12 +216,13 @@ function getNormalizedName(
208
216
if ( route ) {
209
217
// Early return if index route
210
218
if ( route . index ) {
219
+ debugger ;
211
220
return sendIndexPath ( pathBuilder , branch . pathname , basename ) ;
212
221
}
213
222
const path = route . path ;
214
223
215
224
// If path is not a wildcard and has no child routes, append the path
216
- if ( path && ! pathIsWildcardAndHasChildren ( path , branch ) ) {
225
+ if ( path && ! matchIsWildcardAndHasChildren ( path , branch ) ) {
217
226
const newPath = path [ 0 ] === '/' || pathBuilder [ pathBuilder . length - 1 ] === '/' ? path : `/${ path } ` ;
218
227
pathBuilder += newPath ;
219
228
@@ -236,7 +245,7 @@ function getNormalizedName(
236
245
}
237
246
238
247
// if the last character of the pathbuilder is a wildcard and there are children, remove the wildcard
239
- if ( pathIsWildcardAndHasChildren ( pathBuilder , branch ) ) {
248
+ if ( matchIsWildcardAndHasChildren ( pathBuilder , branch ) ) {
240
249
pathBuilder = pathBuilder . slice ( 0 , - 1 ) ;
241
250
}
242
251
@@ -247,23 +256,27 @@ function getNormalizedName(
247
256
}
248
257
}
249
258
259
+ debugger ;
250
260
return [ _stripBasename ? stripBasenameFromPathname ( location . pathname , basename ) : location . pathname , 'url' ] ;
251
261
}
252
262
253
- function updatePageloadTransaction (
254
- activeRootSpan : Span | undefined ,
255
- location : Location ,
256
- routes : RouteObject [ ] ,
257
- matches ?: AgnosticDataRouteMatch ,
258
- basename ?: string ,
259
- allRoutes ?: RouteObject [ ] ,
260
- ) : void {
263
+ function updatePageloadTransaction ( options : {
264
+ activeRootSpan : Span | undefined ;
265
+ location : Location ;
266
+ routes : RouteObject [ ] ;
267
+ matches ?: AgnosticDataRouteMatch ;
268
+ basename ?: string ;
269
+ allRoutes ?: RouteObject [ ] ;
270
+ } ) : void {
271
+ debugger ;
272
+ const { activeRootSpan, location, routes, matches, basename, allRoutes } = options ;
273
+
261
274
const branches = Array . isArray ( matches )
262
275
? matches
263
- : ( _matchRoutes ( routes , location , basename ) as unknown as RouteMatch [ ] ) ;
276
+ : ( _matchRoutes ( allRoutes , location , basename ) as unknown as RouteMatch [ ] ) ;
264
277
265
278
if ( branches ) {
266
- const [ name , source ] = getNormalizedName ( routes , location , branches , basename , allRoutes ) ;
279
+ const [ name , source ] = getNormalizedName ( allRoutes || routes , location , branches , basename , allRoutes ) ;
267
280
268
281
getCurrentScope ( ) . setTransactionName ( name ) ;
269
282
@@ -274,14 +287,16 @@ function updatePageloadTransaction(
274
287
}
275
288
}
276
289
277
- function handleNavigation (
278
- location : Location ,
279
- routes : RouteObject [ ] ,
280
- navigationType : Action ,
281
- matches ?: AgnosticDataRouteMatch ,
282
- basename ?: string ,
283
- allRoutes ?: RouteObject [ ] ,
284
- ) : void {
290
+ function handleNavigation ( options : {
291
+ location : Location ;
292
+ routes : RouteObject [ ] ;
293
+ navigationType : Action ;
294
+ matches ?: AgnosticDataRouteMatch ;
295
+ basename ?: string ;
296
+ allRoutes ?: RouteObject [ ] ;
297
+ } ) : void {
298
+ const { location, routes, navigationType, matches, basename, allRoutes } = options ;
299
+
285
300
const branches = Array . isArray ( matches ) ? matches : _matchRoutes ( routes , location , basename ) ;
286
301
287
302
const client = getClient ( ) ;
@@ -339,15 +354,25 @@ export function withSentryReactRouterV6Routing<P extends Record<string, any>, R
339
354
( ) => {
340
355
const routes = _createRoutesFromChildren ( props . children ) as RouteObject [ ] ;
341
356
342
- routes . forEach ( route => {
343
- allRoutes . push ( ...getChildRoutesRecursively ( route ) ) ;
344
- } ) ;
345
-
346
357
if ( isMountRenderPass ) {
347
- updatePageloadTransaction ( getActiveRootSpan ( ) , location , routes , undefined , undefined , allRoutes ) ;
358
+ routes . forEach ( route => {
359
+ allRoutes . push ( ...getChildRoutesRecursively ( route ) ) ;
360
+ } ) ;
361
+
362
+ updatePageloadTransaction ( {
363
+ activeRootSpan : getActiveRootSpan ( ) ,
364
+ location,
365
+ routes,
366
+ allRoutes,
367
+ } ) ;
348
368
isMountRenderPass = false ;
349
369
} else {
350
- handleNavigation ( location , routes , navigationType , undefined , undefined , allRoutes ) ;
370
+ handleNavigation ( {
371
+ location,
372
+ routes,
373
+ navigationType,
374
+ allRoutes,
375
+ } ) ;
351
376
}
352
377
} ,
353
378
// `props.children` is purposely not included in the dependency array, because we do not want to re-run this effect
@@ -402,15 +427,26 @@ export function wrapUseRoutes(origUseRoutes: UseRoutes): UseRoutes {
402
427
const normalizedLocation =
403
428
typeof stableLocationParam === 'string' ? { pathname : stableLocationParam } : stableLocationParam ;
404
429
405
- routes . forEach ( route => {
406
- allRoutes . push ( ...getChildRoutesRecursively ( route ) ) ;
407
- } ) ;
408
-
409
430
if ( isMountRenderPass ) {
410
- updatePageloadTransaction ( getActiveRootSpan ( ) , normalizedLocation , routes , undefined , undefined , allRoutes ) ;
431
+ routes . forEach ( route => {
432
+ allRoutes . push ( ...getChildRoutesRecursively ( route ) ) ;
433
+ } ) ;
434
+
435
+ updatePageloadTransaction ( {
436
+ activeRootSpan : getActiveRootSpan ( ) ,
437
+ location : normalizedLocation ,
438
+ routes,
439
+ allRoutes,
440
+ } ) ;
441
+
411
442
isMountRenderPass = false ;
412
443
} else {
413
- handleNavigation ( normalizedLocation , routes , navigationType , undefined , undefined , allRoutes ) ;
444
+ handleNavigation ( {
445
+ location : normalizedLocation ,
446
+ routes,
447
+ navigationType,
448
+ allRoutes,
449
+ } ) ;
414
450
}
415
451
} , [ navigationType , stableLocationParam ] ) ;
416
452
@@ -449,13 +485,23 @@ export function wrapCreateBrowserRouter<
449
485
// This is the earliest convenient time to update the transaction name.
450
486
// Callbacks to `router.subscribe` are not called for the initial load.
451
487
if ( router . state . historyAction === 'POP' && activeRootSpan ) {
452
- updatePageloadTransaction ( activeRootSpan , router . state . location , routes , undefined , basename ) ;
488
+ updatePageloadTransaction ( {
489
+ activeRootSpan,
490
+ location : router . state . location ,
491
+ routes,
492
+ basename,
493
+ } ) ;
453
494
}
454
495
455
496
router . subscribe ( ( state : RouterState ) => {
456
497
const location = state . location ;
457
498
if ( state . historyAction === 'PUSH' || state . historyAction === 'POP' ) {
458
- handleNavigation ( location , routes , state . historyAction , undefined , basename ) ;
499
+ handleNavigation ( {
500
+ location,
501
+ routes,
502
+ navigationType : state . historyAction ,
503
+ basename,
504
+ } ) ;
459
505
}
460
506
} ) ;
461
507
0 commit comments