Skip to content

Commit

Permalink
fix(react): Break if path is not changed in recursive rebuild.
Browse files Browse the repository at this point in the history
  • Loading branch information
onurtemizkan committed Feb 4, 2025
1 parent 3c4df06 commit 14e83f6
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions packages/react/src/reactrouterv6-compat-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ export function createV6CompatibleWrapCreateBrowserRouter<

return function (routes: RouteObject[], opts?: Record<string, unknown> & { basename?: string }): TRouter {
routes.forEach(route => {
allRoutes.add(route);
const extractedChildRoutes = getChildRoutesRecursively(route);

extractedChildRoutes.forEach(r => {
allRoutes.add(r);
});
});

const router = createRouterFunction(routes, opts);
Expand Down Expand Up @@ -166,7 +170,11 @@ export function createV6CompatibleWrapCreateMemoryRouter<
},
): TRouter {
routes.forEach(route => {
allRoutes.add(route);
const extractedChildRoutes = getChildRoutesRecursively(route);

extractedChildRoutes.forEach(r => {
allRoutes.add(r);
});
});

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

childRoutes.forEach(r => allRoutes.add(r));
childRoutes.forEach(r => {
allRoutes.add(r);
});
});
}
}
Expand Down Expand Up @@ -498,6 +508,11 @@ function rebuildRoutePathFromAllRoutes(allRoutes: RouteObject[], location: Locat
const path = pickPath(match);
const strippedPath = stripBasenameFromPathname(location.pathname, prefixWithSlash(match.pathnameBase));

if (location.pathname === strippedPath) {
return trimSlash(strippedPath);
}


return trimSlash(
trimSlash(path || '') +
prefixWithSlash(
Expand Down Expand Up @@ -588,6 +603,8 @@ function updatePageloadTransaction(
if (branches) {
let name,
source: TransactionSource = 'url';

debugger;
const isInDescendantRoute = locationIsInsideDescendantRoute(location, allRoutes || routes);

if (isInDescendantRoute) {
Expand Down

0 comments on commit 14e83f6

Please sign in to comment.