@@ -180,7 +180,7 @@ export function createV6CompatibleWrapUseRoutes(origUseRoutes: UseRoutes, versio
180180 return origUseRoutes ;
181181 }
182182
183- const allRoutes : RouteObject [ ] = [ ] ;
183+ const allRoutes : Set < RouteObject > = new Set ( ) ;
184184
185185 const SentryRoutes : React . FC < {
186186 children ?: React . ReactNode ;
@@ -207,18 +207,29 @@ export function createV6CompatibleWrapUseRoutes(origUseRoutes: UseRoutes, versio
207207
208208 if ( isMountRenderPass . current ) {
209209 routes . forEach ( route => {
210- allRoutes . push ( ...getChildRoutesRecursively ( route ) ) ;
210+ const extractedChildRoutes = getChildRoutesRecursively ( route ) ;
211+
212+ extractedChildRoutes . forEach ( r => {
213+ allRoutes . add ( r ) ;
214+ } ) ;
211215 } ) ;
212216
213- updatePageloadTransaction ( getActiveRootSpan ( ) , normalizedLocation , routes , undefined , undefined , allRoutes ) ;
217+ updatePageloadTransaction (
218+ getActiveRootSpan ( ) ,
219+ normalizedLocation ,
220+ routes ,
221+ undefined ,
222+ undefined ,
223+ Array . from ( allRoutes ) ,
224+ ) ;
214225 isMountRenderPass . current = false ;
215226 } else {
216227 handleNavigation ( {
217228 location : normalizedLocation ,
218229 routes,
219230 navigationType,
220231 version,
221- allRoutes,
232+ allRoutes : Array . from ( allRoutes ) ,
222233 } ) ;
223234 }
224235 } , [ navigationType , stableLocationParam ] ) ;
@@ -343,14 +354,18 @@ function locationIsInsideDescendantRoute(location: Location, routes: RouteObject
343354 return false ;
344355}
345356
346- function getChildRoutesRecursively ( route : RouteObject , allRoutes : RouteObject [ ] = [ ] ) : RouteObject [ ] {
347- if ( route . children && ! route . index ) {
348- route . children . forEach ( child => {
349- allRoutes . push ( ...getChildRoutesRecursively ( child , allRoutes ) ) ;
350- } ) ;
351- }
357+ function getChildRoutesRecursively ( route : RouteObject , allRoutes : Set < RouteObject > = new Set ( ) ) : Set < RouteObject > {
358+ if ( ! allRoutes . has ( route ) ) {
359+ allRoutes . add ( route ) ;
352360
353- allRoutes . push ( route ) ;
361+ if ( route . children && ! route . index ) {
362+ route . children . forEach ( child => {
363+ const childRoutes = getChildRoutesRecursively ( child , allRoutes ) ;
364+
365+ childRoutes . forEach ( r => allRoutes . add ( r ) ) ;
366+ } ) ;
367+ }
368+ }
354369
355370 return allRoutes ;
356371}
@@ -513,7 +528,7 @@ export function createV6CompatibleWithSentryReactRouterRouting<P extends Record<
513528 return Routes ;
514529 }
515530
516- const allRoutes : RouteObject [ ] = [ ] ;
531+ const allRoutes : Set < RouteObject > = new Set ( ) ;
517532
518533 const SentryRoutes : React . FC < P > = ( props : P ) => {
519534 const isMountRenderPass = React . useRef ( true ) ;
@@ -527,18 +542,22 @@ export function createV6CompatibleWithSentryReactRouterRouting<P extends Record<
527542
528543 if ( isMountRenderPass . current ) {
529544 routes . forEach ( route => {
530- allRoutes . push ( ...getChildRoutesRecursively ( route ) ) ;
545+ const extractedChildRoutes = getChildRoutesRecursively ( route ) ;
546+
547+ extractedChildRoutes . forEach ( r => {
548+ allRoutes . add ( r ) ;
549+ } ) ;
531550 } ) ;
532551
533- updatePageloadTransaction ( getActiveRootSpan ( ) , location , routes , undefined , undefined , allRoutes ) ;
552+ updatePageloadTransaction ( getActiveRootSpan ( ) , location , routes , undefined , undefined , Array . from ( allRoutes ) ) ;
534553 isMountRenderPass . current = false ;
535554 } else {
536555 handleNavigation ( {
537556 location,
538557 routes,
539558 navigationType,
540559 version,
541- allRoutes,
560+ allRoutes : Array . from ( allRoutes ) ,
542561 } ) ;
543562 }
544563 } ,
0 commit comments