@@ -782,7 +782,7 @@ function patchPageloadSpanEnd(
782782 location : Location ,
783783 routes : RouteObject [ ] ,
784784 basename : string | undefined ,
785- allRoutes : RouteObject [ ] | undefined ,
785+ _allRoutes : RouteObject [ ] | undefined ,
786786) : void {
787787 const hasEndBeenPatched = ( span as { __sentry_pageload_end_patched__ ?: boolean } ) ?. __sentry_pageload_end_patched__ ;
788788
@@ -798,10 +798,18 @@ function patchPageloadSpanEnd(
798798 const currentSource = spanJson . data ?. [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] ;
799799 if ( currentSource !== 'route' ) {
800800 // Last chance to update the transaction name with the latest route info
801- const branches = _matchRoutes ( allRoutes || routes , location , basename ) as unknown as RouteMatch [ ] ;
801+ // Use the live global allRoutes Set to include any lazy routes loaded after patching
802+ const currentAllRoutes = Array . from ( allRoutes ) ;
803+ const branches = _matchRoutes ( currentAllRoutes || routes , location , basename ) as unknown as RouteMatch [ ] ;
802804
803805 if ( branches ) {
804- const [ latestName , latestSource ] = getTransactionNameAndSource ( location , routes , branches , basename , allRoutes ) ;
806+ const [ latestName , latestSource ] = getTransactionNameAndSource (
807+ location ,
808+ routes ,
809+ branches ,
810+ basename ,
811+ currentAllRoutes ,
812+ ) ;
805813
806814 span . updateName ( latestName ) ;
807815 span . setAttribute ( SEMANTIC_ATTRIBUTE_SENTRY_SOURCE , latestSource ) ;
@@ -828,7 +836,7 @@ function patchNavigationSpanEnd(
828836 location : Location ,
829837 routes : RouteObject [ ] ,
830838 basename : string | undefined ,
831- allRoutes : RouteObject [ ] | undefined ,
839+ _allRoutes : RouteObject [ ] | undefined ,
832840) : void {
833841 const hasEndBeenPatched = ( span as { __sentry_navigation_end_patched__ ?: boolean } )
834842 ?. __sentry_navigation_end_patched__ ;
@@ -845,10 +853,12 @@ function patchNavigationSpanEnd(
845853 const currentSource = spanJson . data ?. [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] ;
846854 if ( currentSource !== 'route' ) {
847855 // Last chance to update the transaction name with the latest route info
848- const branches = _matchRoutes ( allRoutes || routes , location , basename ) as unknown as RouteMatch [ ] ;
856+ // Use the live global allRoutes Set to include any lazy routes loaded after patching
857+ const currentAllRoutes = Array . from ( allRoutes ) ;
858+ const branches = _matchRoutes ( currentAllRoutes || routes , location , basename ) as unknown as RouteMatch [ ] ;
849859
850860 if ( branches ) {
851- const [ name , source ] = resolveRouteNameAndSource ( location , routes , allRoutes || routes , branches , basename ) ;
861+ const [ name , source ] = resolveRouteNameAndSource ( location , routes , currentAllRoutes , branches , basename ) ;
852862
853863 // Only update if we have a valid name and the span hasn't finished
854864 if ( name && ! spanJson . timestamp ) {
0 commit comments