@@ -44,7 +44,6 @@ import { checkRouteForAsyncHandler } from './lazy-routes';
4444import {
4545 getNormalizedName ,
4646 initializeRouterUtils ,
47- isLikelyLazyRouteContext ,
4847 locationIsInsideDescendantRoute ,
4948 prefixWithSlash ,
5049 rebuildRoutePathFromAllRoutes ,
@@ -176,12 +175,7 @@ export function updateNavigationSpan(
176175 // Check if this span has already been named to avoid multiple updates
177176 // But allow updates if this is a forced update (e.g., when lazy routes are loaded)
178177 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__ ;
185179
186180 if ( ! hasBeenNamed ) {
187181 // Get fresh branches for the current location with all loaded routes
@@ -355,13 +349,7 @@ export function createV6CompatibleWrapCreateMemoryRouter<
355349 : router . state . location ;
356350
357351 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 ) } ) ;
365353 }
366354
367355 router . subscribe ( ( state : RouterState ) => {
@@ -389,11 +377,7 @@ export function createReactRouterV6CompatibleTracingIntegration(
389377 options : Parameters < typeof browserTracingIntegration > [ 0 ] & ReactRouterOptions ,
390378 version : V6CompatibleVersion ,
391379) : Integration {
392- const integration = browserTracingIntegration ( {
393- ...options ,
394- instrumentPageLoad : false ,
395- instrumentNavigation : false ,
396- } ) ;
380+ const integration = browserTracingIntegration ( { ...options , instrumentPageLoad : false , instrumentNavigation : false } ) ;
397381
398382 const {
399383 useEffect,
@@ -532,13 +516,7 @@ function wrapPatchRoutesOnNavigation(
532516 if ( activeRootSpan && ( spanToJSON ( activeRootSpan ) as { op ?: string } ) . op === 'navigation' ) {
533517 updateNavigationSpan (
534518 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' } ,
542520 Array . from ( allRoutes ) ,
543521 true , // forceUpdate = true since we're loading lazy routes
544522 _matchRoutes ,
@@ -559,13 +537,7 @@ function wrapPatchRoutesOnNavigation(
559537 if ( pathname ) {
560538 updateNavigationSpan (
561539 activeRootSpan ,
562- {
563- pathname,
564- search : '' ,
565- hash : '' ,
566- state : null ,
567- key : 'default' ,
568- } ,
540+ { pathname, search : '' , hash : '' , state : null , key : 'default' } ,
569541 Array . from ( allRoutes ) ,
570542 false , // forceUpdate = false since this is after lazy routes are loaded
571543 _matchRoutes ,
@@ -604,18 +576,20 @@ export function handleNavigation(opts: {
604576 basename ,
605577 ) ;
606578
607- // Check if this might be a lazy route context
608- const isLazyRouteContext = isLikelyLazyRouteContext ( allRoutes || routes , location ) ;
609-
610579 const activeSpan = getActiveSpan ( ) ;
611580 const spanJson = activeSpan && spanToJSON ( activeSpan ) ;
612581 const isAlreadyInNavigationSpan = spanJson ?. op === 'navigation' ;
613582
614583 // 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+ } ) ;
619593 }
620594 }
621595}
@@ -726,13 +700,7 @@ export function createV6CompatibleWithSentryReactRouterRouting<P extends Record<
726700 } ) ;
727701 isMountRenderPass . current = false ;
728702 } 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 ) } ) ;
736704 }
737705 } ,
738706 // `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 {
765733 // Only use this root span if it is a pageload or navigation span
766734 return op === 'navigation' || op === 'pageload' ? rootSpan : undefined ;
767735}
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