Skip to content

Commit 14e83f6

Browse files
committed
fix(react): Break if path is not changed in recursive rebuild.
1 parent 3c4df06 commit 14e83f6

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

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

+20-3
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ export function createV6CompatibleWrapCreateBrowserRouter<
8585

8686
return function (routes: RouteObject[], opts?: Record<string, unknown> & { basename?: string }): TRouter {
8787
routes.forEach(route => {
88-
allRoutes.add(route);
88+
const extractedChildRoutes = getChildRoutesRecursively(route);
89+
90+
extractedChildRoutes.forEach(r => {
91+
allRoutes.add(r);
92+
});
8993
});
9094

9195
const router = createRouterFunction(routes, opts);
@@ -166,7 +170,11 @@ export function createV6CompatibleWrapCreateMemoryRouter<
166170
},
167171
): TRouter {
168172
routes.forEach(route => {
169-
allRoutes.add(route);
173+
const extractedChildRoutes = getChildRoutesRecursively(route);
174+
175+
extractedChildRoutes.forEach(r => {
176+
allRoutes.add(r);
177+
});
170178
});
171179

172180
const router = createRouterFunction(routes, opts);
@@ -458,7 +466,9 @@ function getChildRoutesRecursively(route: RouteObject, allRoutes: Set<RouteObjec
458466
route.children.forEach(child => {
459467
const childRoutes = getChildRoutesRecursively(child, allRoutes);
460468

461-
childRoutes.forEach(r => allRoutes.add(r));
469+
childRoutes.forEach(r => {
470+
allRoutes.add(r);
471+
});
462472
});
463473
}
464474
}
@@ -498,6 +508,11 @@ function rebuildRoutePathFromAllRoutes(allRoutes: RouteObject[], location: Locat
498508
const path = pickPath(match);
499509
const strippedPath = stripBasenameFromPathname(location.pathname, prefixWithSlash(match.pathnameBase));
500510

511+
if (location.pathname === strippedPath) {
512+
return trimSlash(strippedPath);
513+
}
514+
515+
501516
return trimSlash(
502517
trimSlash(path || '') +
503518
prefixWithSlash(
@@ -588,6 +603,8 @@ function updatePageloadTransaction(
588603
if (branches) {
589604
let name,
590605
source: TransactionSource = 'url';
606+
607+
debugger;
591608
const isInDescendantRoute = locationIsInsideDescendantRoute(location, allRoutes || routes);
592609

593610
if (isInDescendantRoute) {

0 commit comments

Comments
 (0)