@@ -44,7 +44,6 @@ import { checkRouteForAsyncHandler } from './lazy-routes';
44
44
import {
45
45
getNormalizedName ,
46
46
initializeRouterUtils ,
47
- isLikelyLazyRouteContext ,
48
47
locationIsInsideDescendantRoute ,
49
48
prefixWithSlash ,
50
49
rebuildRoutePathFromAllRoutes ,
@@ -176,12 +175,7 @@ export function updateNavigationSpan(
176
175
// Check if this span has already been named to avoid multiple updates
177
176
// But allow updates if this is a forced update (e.g., when lazy routes are loaded)
178
177
const hasBeenNamed =
179
- ! forceUpdate &&
180
- (
181
- activeRootSpan as {
182
- __sentry_navigation_name_set__ ?: boolean ;
183
- }
184
- ) ?. __sentry_navigation_name_set__ ;
178
+ ! forceUpdate && ( activeRootSpan as { __sentry_navigation_name_set__ ?: boolean } ) ?. __sentry_navigation_name_set__ ;
185
179
186
180
if ( ! hasBeenNamed ) {
187
181
// Get fresh branches for the current location with all loaded routes
@@ -355,13 +349,7 @@ export function createV6CompatibleWrapCreateMemoryRouter<
355
349
: router . state . location ;
356
350
357
351
if ( router . state . historyAction === 'POP' && activeRootSpan ) {
358
- updatePageloadTransaction ( {
359
- activeRootSpan,
360
- location,
361
- routes,
362
- basename,
363
- allRoutes : Array . from ( allRoutes ) ,
364
- } ) ;
352
+ updatePageloadTransaction ( { activeRootSpan, location, routes, basename, allRoutes : Array . from ( allRoutes ) } ) ;
365
353
}
366
354
367
355
router . subscribe ( ( state : RouterState ) => {
@@ -389,11 +377,7 @@ export function createReactRouterV6CompatibleTracingIntegration(
389
377
options : Parameters < typeof browserTracingIntegration > [ 0 ] & ReactRouterOptions ,
390
378
version : V6CompatibleVersion ,
391
379
) : Integration {
392
- const integration = browserTracingIntegration ( {
393
- ...options ,
394
- instrumentPageLoad : false ,
395
- instrumentNavigation : false ,
396
- } ) ;
380
+ const integration = browserTracingIntegration ( { ...options , instrumentPageLoad : false , instrumentNavigation : false } ) ;
397
381
398
382
const {
399
383
useEffect,
@@ -532,13 +516,7 @@ function wrapPatchRoutesOnNavigation(
532
516
if ( activeRootSpan && ( spanToJSON ( activeRootSpan ) as { op ?: string } ) . op === 'navigation' ) {
533
517
updateNavigationSpan (
534
518
activeRootSpan ,
535
- {
536
- pathname : targetPath ,
537
- search : '' ,
538
- hash : '' ,
539
- state : null ,
540
- key : 'default' ,
541
- } ,
519
+ { pathname : targetPath , search : '' , hash : '' , state : null , key : 'default' } ,
542
520
Array . from ( allRoutes ) ,
543
521
true , // forceUpdate = true since we're loading lazy routes
544
522
_matchRoutes ,
@@ -559,13 +537,7 @@ function wrapPatchRoutesOnNavigation(
559
537
if ( pathname ) {
560
538
updateNavigationSpan (
561
539
activeRootSpan ,
562
- {
563
- pathname,
564
- search : '' ,
565
- hash : '' ,
566
- state : null ,
567
- key : 'default' ,
568
- } ,
540
+ { pathname, search : '' , hash : '' , state : null , key : 'default' } ,
569
541
Array . from ( allRoutes ) ,
570
542
false , // forceUpdate = false since this is after lazy routes are loaded
571
543
_matchRoutes ,
@@ -604,18 +576,20 @@ export function handleNavigation(opts: {
604
576
basename ,
605
577
) ;
606
578
607
- // Check if this might be a lazy route context
608
- const isLazyRouteContext = isLikelyLazyRouteContext ( allRoutes || routes , location ) ;
609
-
610
579
const activeSpan = getActiveSpan ( ) ;
611
580
const spanJson = activeSpan && spanToJSON ( activeSpan ) ;
612
581
const isAlreadyInNavigationSpan = spanJson ?. op === 'navigation' ;
613
582
614
583
// Cross usage can result in multiple navigation spans being created without this check
615
- if ( isAlreadyInNavigationSpan && activeSpan && spanJson ) {
616
- handleExistingNavigationSpan ( activeSpan , spanJson , name , source , isLazyRouteContext ) ;
617
- } else {
618
- createNewNavigationSpan ( client , name , source , version , isLazyRouteContext ) ;
584
+ if ( ! isAlreadyInNavigationSpan ) {
585
+ startBrowserTracingNavigationSpan ( client , {
586
+ name,
587
+ attributes : {
588
+ [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : source ,
589
+ [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : 'navigation' ,
590
+ [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : `auto.navigation.react.reactrouter_v${ version } ` ,
591
+ } ,
592
+ } ) ;
619
593
}
620
594
}
621
595
}
@@ -726,13 +700,7 @@ export function createV6CompatibleWithSentryReactRouterRouting<P extends Record<
726
700
} ) ;
727
701
isMountRenderPass . current = false ;
728
702
} else {
729
- handleNavigation ( {
730
- location,
731
- routes,
732
- navigationType,
733
- version,
734
- allRoutes : Array . from ( allRoutes ) ,
735
- } ) ;
703
+ handleNavigation ( { location, routes, navigationType, version, allRoutes : Array . from ( allRoutes ) } ) ;
736
704
}
737
705
} ,
738
706
// `props.children` is purposely not included in the dependency array, because we do not want to re-run this effect
@@ -765,69 +733,3 @@ function getActiveRootSpan(): Span | undefined {
765
733
// Only use this root span if it is a pageload or navigation span
766
734
return op === 'navigation' || op === 'pageload' ? rootSpan : undefined ;
767
735
}
768
-
769
- /**
770
- * Handles updating an existing navigation span
771
- */
772
- export function handleExistingNavigationSpan (
773
- activeSpan : Span ,
774
- spanJson : ReturnType < typeof spanToJSON > ,
775
- name : string ,
776
- source : TransactionSource ,
777
- isLikelyLazyRoute : boolean ,
778
- ) : void {
779
- // Check if we've already set the name for this span using a custom property
780
- const hasBeenNamed = (
781
- activeSpan as {
782
- __sentry_navigation_name_set__ ?: boolean ;
783
- }
784
- ) ?. __sentry_navigation_name_set__ ;
785
-
786
- if ( ! hasBeenNamed ) {
787
- // This is the first time we're setting the name for this span
788
- if ( ! spanJson . timestamp ) {
789
- activeSpan ?. updateName ( name ) ;
790
- }
791
-
792
- // For lazy routes, don't mark as named yet so it can be updated later
793
- if ( ! isLikelyLazyRoute ) {
794
- addNonEnumerableProperty (
795
- activeSpan as { __sentry_navigation_name_set__ ?: boolean } ,
796
- '__sentry_navigation_name_set__' ,
797
- true ,
798
- ) ;
799
- }
800
- }
801
-
802
- // Always set the source attribute to keep it consistent with the current route
803
- activeSpan ?. setAttribute ( SEMANTIC_ATTRIBUTE_SENTRY_SOURCE , source ) ;
804
- }
805
-
806
- /**
807
- * Creates a new navigation span
808
- */
809
- export function createNewNavigationSpan (
810
- client : Client ,
811
- name : string ,
812
- source : TransactionSource ,
813
- version : string ,
814
- isLikelyLazyRoute : boolean ,
815
- ) : void {
816
- const newSpan = startBrowserTracingNavigationSpan ( client , {
817
- name,
818
- attributes : {
819
- [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : source ,
820
- [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : 'navigation' ,
821
- [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : `auto.navigation.react.reactrouter_v${ version } ` ,
822
- } ,
823
- } ) ;
824
-
825
- // For lazy routes, don't mark as named yet so it can be updated later when the route loads
826
- if ( ! isLikelyLazyRoute && newSpan ) {
827
- addNonEnumerableProperty (
828
- newSpan as { __sentry_navigation_name_set__ ?: boolean } ,
829
- '__sentry_navigation_name_set__' ,
830
- true ,
831
- ) ;
832
- }
833
- }
0 commit comments