Skip to content

Commit

Permalink
chore: add some comments, mark the next route as the conflict
Browse files Browse the repository at this point in the history
Signed-off-by: Logan McAnsh <logan@mcan.sh>
  • Loading branch information
mcansh committed Feb 17, 2023
1 parent efb065a commit e8447f0
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/remix-dev/config/flat-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,36 +360,41 @@ function getRouteMap(
return b.segments.length - a.segments.length;
});

// update parentIds for all routes
for (let i = 0; i < routes.length; i++) {
let routeInfo = routes[i];
// update parentIds for all routes
routeInfo.parentId = findParentRouteId(routeInfo, nameMap);

// remove routes that conflict with other routes
let nextRouteInfo = routes[i + 1];
if (!nextRouteInfo) continue;

let segments = routeInfo.segments;
let nextSegments = nextRouteInfo.segments;
// if segment count is different, there can't be a conflict
if (segments.length !== nextSegments.length) continue;

for (let k = 0; k < segments.length; k++) {
let segment = segments[k];
let nextSegment = nextSegments[k];

// if segments are different, but they're both dynamic, there's a conflict
if (
segment !== nextSegment &&
segment.startsWith(":") &&
nextSegment.startsWith(":")
) {
let currentConflicts = conflicts.get(routeInfo.path || "/");
// collect conflicts for later reporting, marking the next route as the conflicting route
if (!currentConflicts) {
conflicts.set(routeInfo.path || "/", [routeInfo, nextRouteInfo]);
} else {
currentConflicts.push(nextRouteInfo);
conflicts.set(routeInfo.path || "/", currentConflicts);
}

routeMap.delete(routeInfo.id);
// remove conflicting route
routeMap.delete(nextRouteInfo.id);

continue;
}
Expand Down

0 comments on commit e8447f0

Please sign in to comment.