@@ -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
@@ -226,42 +235,48 @@ function getNormalizedName(
226
235
// If the route defined on the element is something like
227
236
// <Route path="/stores/:storeId/products/:productId" element={<div>Product</div>} />
228
237
// We should check against the branch.pathname for the number of / separators
229
- getNumberOfUrlSegments ( pathBuilder ) !== getNumberOfUrlSegments ( branch . pathname ) &&
230
- // We should not count wildcard operators in the url segments calculation
231
- ! pathEndsWithWildcard ( pathBuilder )
238
+ getNumberOfUrlSegments ( pathBuilder ) === getNumberOfUrlSegments ( branch . pathname ) // &&
239
+ // // We should not count wildcard operators in the url segments calculation
240
+ // !pathEndsWithWildcard(pathBuilder)
232
241
) {
242
+ debugger
233
243
return [ ( _stripBasename ? '' : basename ) + newPath , 'route' ] ;
234
244
}
235
245
236
246
// if the last character of the pathbuilder is a wildcard and there are children, remove the wildcard
237
- if ( pathIsWildcardAndHasChildren ( pathBuilder , branch ) ) {
247
+ if ( matchIsWildcardAndHasChildren ( pathBuilder , branch ) ) {
238
248
pathBuilder = pathBuilder . slice ( 0 , - 1 ) ;
239
249
}
240
250
251
+ debugger ;
241
252
return [ ( _stripBasename ? '' : basename ) + pathBuilder , 'route' ] ;
242
253
}
243
254
}
244
255
}
245
256
}
246
257
}
247
258
259
+ debugger ;
248
260
return [ _stripBasename ? stripBasenameFromPathname ( location . pathname , basename ) : location . pathname , 'url' ] ;
249
261
}
250
262
251
- function updatePageloadTransaction (
252
- activeRootSpan : Span | undefined ,
253
- location : Location ,
254
- routes : RouteObject [ ] ,
255
- matches ?: AgnosticDataRouteMatch ,
256
- basename ?: string ,
257
- allRoutes ?: RouteObject [ ] ,
258
- ) : 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
+
259
274
const branches = Array . isArray ( matches )
260
275
? matches
261
- : ( _matchRoutes ( routes , location , basename ) as unknown as RouteMatch [ ] ) ;
276
+ : ( _matchRoutes ( allRoutes , location , basename ) as unknown as RouteMatch [ ] ) ;
262
277
263
278
if ( branches ) {
264
- const [ name , source ] = getNormalizedName ( routes , location , branches , basename , allRoutes ) ;
279
+ const [ name , source ] = getNormalizedName ( allRoutes || routes , location , branches , basename , allRoutes ) ;
265
280
266
281
getCurrentScope ( ) . setTransactionName ( name ) ;
267
282
@@ -272,14 +287,16 @@ function updatePageloadTransaction(
272
287
}
273
288
}
274
289
275
- function handleNavigation (
276
- location : Location ,
277
- routes : RouteObject [ ] ,
278
- navigationType : Action ,
279
- matches ?: AgnosticDataRouteMatch ,
280
- basename ?: string ,
281
- allRoutes ?: RouteObject [ ] ,
282
- ) : 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
+
283
300
const branches = Array . isArray ( matches ) ? matches : _matchRoutes ( routes , location , basename ) ;
284
301
285
302
const client = getClient ( ) ;
@@ -337,15 +354,25 @@ export function withSentryReactRouterV6Routing<P extends Record<string, any>, R
337
354
( ) => {
338
355
const routes = _createRoutesFromChildren ( props . children ) as RouteObject [ ] ;
339
356
340
- routes . forEach ( route => {
341
- allRoutes . push ( ...getChildRoutesRecursively ( route ) ) ;
342
- } ) ;
343
-
344
357
if ( isMountRenderPass ) {
345
- 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
+ } ) ;
346
368
isMountRenderPass = false ;
347
369
} else {
348
- handleNavigation ( location , routes , navigationType , undefined , undefined , allRoutes ) ;
370
+ handleNavigation ( {
371
+ location,
372
+ routes,
373
+ navigationType,
374
+ allRoutes,
375
+ } ) ;
349
376
}
350
377
} ,
351
378
// `props.children` is purposely not included in the dependency array, because we do not want to re-run this effect
@@ -400,15 +427,26 @@ export function wrapUseRoutes(origUseRoutes: UseRoutes): UseRoutes {
400
427
const normalizedLocation =
401
428
typeof stableLocationParam === 'string' ? { pathname : stableLocationParam } : stableLocationParam ;
402
429
403
- routes . forEach ( route => {
404
- allRoutes . push ( ...getChildRoutesRecursively ( route ) ) ;
405
- } ) ;
406
-
407
430
if ( isMountRenderPass ) {
408
- 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
+
409
442
isMountRenderPass = false ;
410
443
} else {
411
- handleNavigation ( normalizedLocation , routes , navigationType , undefined , undefined , allRoutes ) ;
444
+ handleNavigation ( {
445
+ location : normalizedLocation ,
446
+ routes,
447
+ navigationType,
448
+ allRoutes,
449
+ } ) ;
412
450
}
413
451
} , [ navigationType , stableLocationParam ] ) ;
414
452
@@ -447,13 +485,23 @@ export function wrapCreateBrowserRouter<
447
485
// This is the earliest convenient time to update the transaction name.
448
486
// Callbacks to `router.subscribe` are not called for the initial load.
449
487
if ( router . state . historyAction === 'POP' && activeRootSpan ) {
450
- updatePageloadTransaction ( activeRootSpan , router . state . location , routes , undefined , basename ) ;
488
+ updatePageloadTransaction ( {
489
+ activeRootSpan,
490
+ location : router . state . location ,
491
+ routes,
492
+ basename,
493
+ } ) ;
451
494
}
452
495
453
496
router . subscribe ( ( state : RouterState ) => {
454
497
const location = state . location ;
455
498
if ( state . historyAction === 'PUSH' || state . historyAction === 'POP' ) {
456
- handleNavigation ( location , routes , state . historyAction , undefined , basename ) ;
499
+ handleNavigation ( {
500
+ location,
501
+ routes,
502
+ navigationType : state . historyAction ,
503
+ basename,
504
+ } ) ;
457
505
}
458
506
} ) ;
459
507
0 commit comments