Skip to content

Commit 2e0a521

Browse files
committed
Only run async handler checks when it's enabled on the integration
1 parent e968adf commit 2e0a521

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

dev-packages/e2e-tests/test-applications/react-router-7-lazy-routes/src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Sentry.init({
2626
createRoutesFromChildren,
2727
matchRoutes,
2828
trackFetchStreamPerformance: true,
29+
enableAsyncRouteHandlers: true,
2930
}),
3031
replay,
3132
],

packages/react/src/reactrouterv6-compat-utils.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ let _useNavigationType: UseNavigationType;
4747
let _createRoutesFromChildren: CreateRoutesFromChildren;
4848
let _matchRoutes: MatchRoutes;
4949
let _stripBasename: boolean = false;
50+
let _enableAsyncRouteHandlers: boolean = false;
5051

5152
const 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

6264
type V6CompatibleVersion = '6' | '7';
@@ -116,7 +118,10 @@ function handleAsyncHandlerResult(result: unknown, route: RouteObject, handlerKe
116118
function 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

Comments
 (0)