Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(remix-dev): remove broken param collision check #5560

Merged
merged 4 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/afraid-tigers-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"remix": patch
"@remix-run/dev": patch
---

chore(remix-dev): remove broken param collision check
28 changes: 26 additions & 2 deletions packages/remix-dev/__tests__/flat-routes-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,31 @@ describe("flatRoutes", () => {
}
});

describe("doesn't warn when there's not a route collision", () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test case is here for when param collision is brought back

let consoleError = jest
.spyOn(global.console, "error")
.mockImplementation(() => {});

afterEach(consoleError.mockReset);

test("same number of segments and the same dynamic segment index", () => {
let testFiles = [
"routes/_user.$username.tsx",
"routes/sneakers.$sneakerId.tsx",
];

let routeManifest = flatRoutesUniversal(
APP_DIR,
testFiles.map((file) => path.join(APP_DIR, normalizePath(file)))
);

let routes = Object.values(routeManifest);

expect(routes).toHaveLength(testFiles.length);
expect(consoleError).not.toHaveBeenCalled();
});
});

describe("warns when there's a route collision", () => {
let consoleError = jest
.spyOn(global.console, "error")
Expand All @@ -627,7 +652,6 @@ describe("flatRoutes", () => {
afterEach(consoleError.mockReset);

test("index files", () => {
// we'll add file manually before running the tests
let testFiles = [
"routes/_dashboard._index.tsx",
"routes/_landing._index.tsx",
Expand Down Expand Up @@ -666,7 +690,7 @@ describe("flatRoutes", () => {
);
});

test("same path, different param name", () => {
test.skip("same path, different param name", () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove skip once new conflict detection is brought in

// we'll add file manually before running the tests
let testFiles = [
"routes/products.$pid.tsx",
Expand Down
38 changes: 1 addition & 37 deletions packages/remix-dev/config/flat-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,45 +360,9 @@ function getRouteMap(
return b.segments.length - a.segments.length;
});

for (let i = 0; i < routes.length; i++) {
let routeInfo = routes[i];
for (let routeInfo of routes) {
// 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);
}

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

continue;
}
}
}

// report conflicts
Expand Down