diff --git a/.changeset/afraid-tigers-occur.md b/.changeset/afraid-tigers-occur.md new file mode 100644 index 00000000000..48be7961e23 --- /dev/null +++ b/.changeset/afraid-tigers-occur.md @@ -0,0 +1,6 @@ +--- +"remix": patch +"@remix-run/dev": patch +--- + +chore(remix-dev): remove broken param collision check diff --git a/packages/remix-dev/__tests__/flat-routes-test.ts b/packages/remix-dev/__tests__/flat-routes-test.ts index 437d1e3216b..6d947295b6f 100644 --- a/packages/remix-dev/__tests__/flat-routes-test.ts +++ b/packages/remix-dev/__tests__/flat-routes-test.ts @@ -619,6 +619,31 @@ describe("flatRoutes", () => { } }); + describe("doesn't warn when there's not a route collision", () => { + 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") @@ -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", @@ -666,7 +690,7 @@ describe("flatRoutes", () => { ); }); - test("same path, different param name", () => { + test.skip("same path, different param name", () => { // we'll add file manually before running the tests let testFiles = [ "routes/products.$pid.tsx", diff --git a/packages/remix-dev/config/flat-routes.ts b/packages/remix-dev/config/flat-routes.ts index eb9224c237e..2d5fc19d2f0 100644 --- a/packages/remix-dev/config/flat-routes.ts +++ b/packages/remix-dev/config/flat-routes.ts @@ -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