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

refactor(remix-dev): flat routes perf improvements #5634

Merged
merged 13 commits into from
Mar 20, 2023
6 changes: 6 additions & 0 deletions .changeset/flat-routes-perf.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"remix": patch
"@remix-run/dev": patch
---

flat routes perf improvements
67 changes: 65 additions & 2 deletions integration/flat-routes-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@ let fixture: Fixture;
let appFixture: AppFixture;

test.describe("flat routes", () => {
let IGNORED_ROUTE = "/ignore-me-pls";
test.beforeAll(async () => {
fixture = await createFixture({
future: { v2_routeConvention: true },
files: {
"remix.config.js": js`
/** @type {import('@remix-run/dev').AppConfig} */
module.exports = {
future: {
v2_routeConvention: true,
},
ignoredRouteFiles: ['${IGNORED_ROUTE}'],
};
`,
"app/root.jsx": js`
import { Links, Meta, Outlet, Scripts } from "@remix-run/react";

Expand Down Expand Up @@ -79,6 +88,12 @@ test.describe("flat routes", () => {
return <h3>Dashboard Index</h3>;
}
`,

[`app/routes/${IGNORED_ROUTE}.jsx`]: js`
export default function () {
return <h2>i should 404</h2>;
}
`,
},
});

Expand Down Expand Up @@ -146,6 +161,12 @@ test.describe("flat routes", () => {
</div>`);
});
}

test("allows ignoredRouteFiles to be configured", async ({ page }) => {
let routeIds = Object.keys(fixture.build.routes);

expect(routeIds).not.toContain(IGNORED_ROUTE);
});
});

test.describe("warns when v1 routesConvention is used", () => {
Expand Down Expand Up @@ -188,7 +209,7 @@ test.describe("warns when v1 routesConvention is used", () => {
console.error = originalConsoleError;
});

test("warns about conflicting routes", () => {
test("v2_routeConvention is not enabled", () => {
console.log(buildOutput);
expect(buildOutput).toContain(flatRoutesWarning);
});
Expand Down Expand Up @@ -249,3 +270,45 @@ test.describe("emits warnings for route conflicts", async () => {
expect(buildOutput).toContain(`⚠️ Route Path Collision: "/"`);
});
});

test.describe("", () => {
let buildStdio = new PassThrough();
let buildOutput: string;

let originalConsoleLog = console.log;
let originalConsoleWarn = console.warn;
let originalConsoleError = console.error;

test.beforeAll(async () => {
console.log = () => {};
console.warn = () => {};
console.error = () => {};
await createFixtureProject({
buildStdio,
future: { v2_routeConvention: true },
files: {
"app/routes/_index/route.jsx": js``,
"app/routes/_index/utils.js": js``,
},
});

let chunks: Buffer[] = [];
buildOutput = await new Promise<string>((resolve, reject) => {
buildStdio.on("data", (chunk) => chunks.push(Buffer.from(chunk)));
buildStdio.on("error", (err) => reject(err));
buildStdio.on("end", () =>
resolve(Buffer.concat(chunks).toString("utf8"))
);
});
});

test.afterAll(() => {
console.log = originalConsoleLog;
console.warn = originalConsoleWarn;
console.error = originalConsoleError;
});

test("doesn't emit a warning for nested index files with co-located files", () => {
expect(buildOutput).not.toContain(`Route Path Collision`);
});
});
Loading