@@ -47,6 +47,7 @@ let _useNavigationType: UseNavigationType;
4747let  _createRoutesFromChildren : CreateRoutesFromChildren ; 
4848let  _matchRoutes : MatchRoutes ; 
4949let  _stripBasename : boolean  =  false ; 
50+ let  _enableAsyncRouteHandlers : boolean  =  false ; 
5051
5152const  CLIENTS_WITH_INSTRUMENT_NAVIGATION  =  new  WeakSet < Client > ( ) ; 
5253
@@ -57,6 +58,7 @@ export interface ReactRouterOptions {
5758  createRoutesFromChildren : CreateRoutesFromChildren ; 
5859  matchRoutes : MatchRoutes ; 
5960  stripBasename ?: boolean ; 
61+   enableAsyncRouteHandlers ?: boolean ; 
6062} 
6163
6264type  V6CompatibleVersion  =  '6'  |  '7' ; 
@@ -116,7 +118,10 @@ function handleAsyncHandlerResult(result: unknown, route: RouteObject, handlerKe
116118function  processResolvedRoutes ( resolvedRoutes : RouteObject [ ] ,  parentRoute ?: RouteObject ) : void   { 
117119  resolvedRoutes . forEach ( child  =>  { 
118120    allRoutes . add ( child ) ; 
119-     checkRouteForAsyncHandler ( child ) ; 
121+     // Only check for async handlers if the feature is enabled 
122+     if  ( _enableAsyncRouteHandlers )  { 
123+       checkRouteForAsyncHandler ( child ) ; 
124+     } 
120125  } ) ; 
121126
122127  if  ( parentRoute )  { 
@@ -207,9 +212,11 @@ export function createV6CompatibleWrapCreateBrowserRouter<
207212  return  function  ( routes : RouteObject [ ] ,  opts ?: Record < string ,  unknown >  &  {  basename ?: string  } ) : TRouter  { 
208213    addRoutesToAllRoutes ( routes ) ; 
209214
210-     // Check for async handlers that might contain sub-route declarations 
211-     for  ( const  route  of  routes )  { 
212-       checkRouteForAsyncHandler ( route ) ; 
215+     // Check for async handlers that might contain sub-route declarations (only if enabled) 
216+     if  ( _enableAsyncRouteHandlers )  { 
217+       for  ( const  route  of  routes )  { 
218+         checkRouteForAsyncHandler ( route ) ; 
219+       } 
213220    } 
214221
215222    const  router  =  createRouterFunction ( routes ,  opts ) ; 
@@ -291,6 +298,13 @@ export function createV6CompatibleWrapCreateMemoryRouter<
291298  ) : TRouter  { 
292299    addRoutesToAllRoutes ( routes ) ; 
293300
301+     // Check for async handlers that might contain sub-route declarations (only if enabled) 
302+     if  ( _enableAsyncRouteHandlers )  { 
303+       for  ( const  route  of  routes )  { 
304+         checkRouteForAsyncHandler ( route ) ; 
305+       } 
306+     } 
307+ 
294308    const  router  =  createRouterFunction ( routes ,  opts ) ; 
295309    const  basename  =  opts ?. basename ; 
296310
@@ -357,6 +371,7 @@ export function createReactRouterV6CompatibleTracingIntegration(
357371    createRoutesFromChildren, 
358372    matchRoutes, 
359373    stripBasename, 
374+     enableAsyncRouteHandlers =  false , 
360375    instrumentPageLoad =  true , 
361376    instrumentNavigation =  true , 
362377  }  =  options ; 
@@ -372,6 +387,7 @@ export function createReactRouterV6CompatibleTracingIntegration(
372387      _matchRoutes  =  matchRoutes ; 
373388      _createRoutesFromChildren  =  createRoutesFromChildren ; 
374389      _stripBasename  =  stripBasename  ||  false ; 
390+       _enableAsyncRouteHandlers  =  enableAsyncRouteHandlers ; 
375391    } , 
376392    afterAllSetup ( client )  { 
377393      integration . afterAllSetup ( client ) ; 
0 commit comments