@@ -47,6 +47,7 @@ let _useNavigationType: UseNavigationType;
47
47
let _createRoutesFromChildren : CreateRoutesFromChildren ;
48
48
let _matchRoutes : MatchRoutes ;
49
49
let _stripBasename : boolean = false ;
50
+ let _enableAsyncRouteHandlers : boolean = false ;
50
51
51
52
const CLIENTS_WITH_INSTRUMENT_NAVIGATION = new WeakSet < Client > ( ) ;
52
53
@@ -57,6 +58,7 @@ export interface ReactRouterOptions {
57
58
createRoutesFromChildren : CreateRoutesFromChildren ;
58
59
matchRoutes : MatchRoutes ;
59
60
stripBasename ?: boolean ;
61
+ enableAsyncRouteHandlers ?: boolean ;
60
62
}
61
63
62
64
type V6CompatibleVersion = '6' | '7' ;
@@ -116,7 +118,10 @@ function handleAsyncHandlerResult(result: unknown, route: RouteObject, handlerKe
116
118
function processResolvedRoutes ( resolvedRoutes : RouteObject [ ] , parentRoute ?: RouteObject ) : void {
117
119
resolvedRoutes . forEach ( child => {
118
120
allRoutes . add ( child ) ;
119
- checkRouteForAsyncHandler ( child ) ;
121
+ // Only check for async handlers if the feature is enabled
122
+ if ( _enableAsyncRouteHandlers ) {
123
+ checkRouteForAsyncHandler ( child ) ;
124
+ }
120
125
} ) ;
121
126
122
127
if ( parentRoute ) {
@@ -207,9 +212,11 @@ export function createV6CompatibleWrapCreateBrowserRouter<
207
212
return function ( routes : RouteObject [ ] , opts ?: Record < string , unknown > & { basename ?: string } ) : TRouter {
208
213
addRoutesToAllRoutes ( routes ) ;
209
214
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
+ }
213
220
}
214
221
215
222
const router = createRouterFunction ( routes , opts ) ;
@@ -291,6 +298,13 @@ export function createV6CompatibleWrapCreateMemoryRouter<
291
298
) : TRouter {
292
299
addRoutesToAllRoutes ( routes ) ;
293
300
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
+
294
308
const router = createRouterFunction ( routes , opts ) ;
295
309
const basename = opts ?. basename ;
296
310
@@ -357,6 +371,7 @@ export function createReactRouterV6CompatibleTracingIntegration(
357
371
createRoutesFromChildren,
358
372
matchRoutes,
359
373
stripBasename,
374
+ enableAsyncRouteHandlers = false ,
360
375
instrumentPageLoad = true ,
361
376
instrumentNavigation = true ,
362
377
} = options ;
@@ -372,6 +387,7 @@ export function createReactRouterV6CompatibleTracingIntegration(
372
387
_matchRoutes = matchRoutes ;
373
388
_createRoutesFromChildren = createRoutesFromChildren ;
374
389
_stripBasename = stripBasename || false ;
390
+ _enableAsyncRouteHandlers = enableAsyncRouteHandlers ;
375
391
} ,
376
392
afterAllSetup ( client ) {
377
393
integration . afterAllSetup ( client ) ;
0 commit comments