Skip to content

Commit

Permalink
Fix splat route index matching (#6130)
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 authored Apr 24, 2023
1 parent 6fd8ee4 commit e48bdff
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/splat-index-matching.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/dev": patch
---

Fix a bug in route matching that wass preventing a single splat (`$.jsx`) route from matching a root `/` path
5 changes: 5 additions & 0 deletions integration/revalidate-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ test.describe("Revalidation", () => {
}
`,

"app/routes/_index.jsx": js`
export default function Component() {
return <h1>Index</h1>;
}
`,
"app/routes/parent.jsx": js`
import { json } from "@remix-run/node";
import { Outlet, useLoaderData } from "@remix-run/react";
Expand Down
106 changes: 104 additions & 2 deletions integration/splat-routes-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { test, expect } from "@playwright/test";
import { createFixture, js } from "./helpers/create-fixture";
import type { Fixture } from "./helpers/create-fixture";

test.describe("rendering", () => {
let fixture: Fixture;
let fixture: Fixture;

test.describe("rendering", () => {
let ROOT_$ = "FLAT";
let ROOT_INDEX = "ROOT_INDEX";
let FLAT_$ = "FLAT";
Expand Down Expand Up @@ -128,3 +128,105 @@ test.describe("rendering", () => {
expect(await res.text()).toMatch(PARENTLESS_$);
});
});

test.describe("root splat route without index", () => {
test("matches routes correctly (v1)", async ({ page }) => {
fixture = await createFixture({
future: { v2_routeConvention: false },
files: {
"app/routes/$.jsx": js`
export default function Component() {
return <h1>Hello Splat</h1>
}
`,
},
});

let res = await fixture.requestDocument("/");
expect(await res.text()).toMatch("Hello Splat");

res = await fixture.requestDocument("/splat");
expect(await res.text()).toMatch("Hello Splat");

res = await fixture.requestDocument("/splat/deep/path");
expect(await res.text()).toMatch("Hello Splat");
});

test("matches routes correctly (v2)", async ({ page }) => {
fixture = await createFixture({
future: { v2_routeConvention: true },
files: {
"app/routes/$.jsx": js`
export default function Component() {
return <h1>Hello Splat</h1>
}
`,
},
});

let res = await fixture.requestDocument("/");
expect(await res.text()).toMatch("Hello Splat");

res = await fixture.requestDocument("/splat");
expect(await res.text()).toMatch("Hello Splat");

res = await fixture.requestDocument("/splat/deep/path");
expect(await res.text()).toMatch("Hello Splat");
});
});

test.describe("root splat route with index", () => {
test("matches routes correctly (v1)", async ({ page }) => {
fixture = await createFixture({
future: { v2_routeConvention: false },
files: {
"app/routes/index.jsx": js`
export default function Component() {
return <h1>Hello Index</h1>
}
`,
"app/routes/$.jsx": js`
export default function Component() {
return <h1>Hello Splat</h1>
}
`,
},
});

let res = await fixture.requestDocument("/");
expect(await res.text()).toMatch("Hello Index");

res = await fixture.requestDocument("/splat");
expect(await res.text()).toMatch("Hello Splat");

res = await fixture.requestDocument("/splat/deep/path");
expect(await res.text()).toMatch("Hello Splat");
});

test("matches routes correctly (v2)", async ({ page }) => {
fixture = await createFixture({
future: { v2_routeConvention: true },
files: {
"app/routes/_index.jsx": js`
export default function Component() {
return <h1>Hello Index</h1>
}
`,
"app/routes/$.jsx": js`
export default function Component() {
return <h1>Hello Splat</h1>
}
`,
},
});

let res = await fixture.requestDocument("/");
expect(await res.text()).toMatch("Hello Index");

res = await fixture.requestDocument("/splat");
expect(await res.text()).toMatch("Hello Splat");

res = await fixture.requestDocument("/splat/deep/path");
expect(await res.text()).toMatch("Hello Splat");
});
});
1 change: 0 additions & 1 deletion packages/remix-dev/__tests__/readConfig-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ describe("readConfig", () => {
"root": Object {
"file": "root.tsx",
"id": "root",
"path": "",
},
},
"serverBuildPath": Any<String>,
Expand Down
2 changes: 1 addition & 1 deletion packages/remix-dev/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ export async function readConfig(
}

let routes: RouteManifest = {
root: { path: "", id: "root", file: rootRouteFile },
root: { id: "root", file: rootRouteFile },
};

let routesConvention: typeof flatRoutes;
Expand Down

0 comments on commit e48bdff

Please sign in to comment.