-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vite): strict route exports (#8171)
- Loading branch information
Showing
4 changed files
with
179 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
"@remix-run/dev": minor | ||
--- | ||
|
||
Vite: Strict route exports | ||
|
||
With Vite, Remix gets stricter about which exports are allowed from your route modules. | ||
Previously, the Remix compiler would allow any export from routes. | ||
While this was convenient, it was also a common source of bugs that were hard to track down because they only surfaced at runtime. | ||
|
||
For more, see https://remix.run/docs/en/main/future/vite#strict-route-exports |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { test, expect } from "@playwright/test"; | ||
|
||
import { createProject, viteBuild } from "./helpers/vite.js"; | ||
|
||
test("Vite / invalid route exports / expected build error", async () => { | ||
let cwd = await createProject({ | ||
"app/routes/fail-non-remix-exports.tsx": String.raw` | ||
// Remix exports | ||
export const ErrorBoundary = () => {} | ||
export const action = () => {} | ||
export const handle = () => {} | ||
export const headers = () => {} | ||
export const links = () => {} | ||
export const loader = () => {} | ||
export const meta = () => {} | ||
export const shouldRevalidate = () => {} | ||
export default function() {} | ||
// Non-Remix exports | ||
export const invalid1 = 1; | ||
export const invalid2 = 2; | ||
`, | ||
}); | ||
let client = viteBuild({ cwd })[0]; | ||
let stderr = client.stderr.toString("utf8"); | ||
expect(stderr).toMatch( | ||
"2 invalid route exports in `routes/fail-non-remix-exports.tsx`:\n - `invalid1`\n - `invalid2`" | ||
); | ||
expect(stderr).toMatch( | ||
"See https://remix.run/docs/en/main/future/vite#strict-route-exports" | ||
); | ||
}); | ||
|
||
test("Vite / invalid route exports / ignore in mdx", async () => { | ||
let cwd = await createProject({ | ||
"vite.config.ts": String.raw` | ||
import { defineConfig } from "vite"; | ||
import { unstable_vitePlugin as remix } from "@remix-run/dev"; | ||
import mdx from "@mdx-js/rollup"; | ||
export default defineConfig({ | ||
plugins: [ | ||
remix(), | ||
mdx(), | ||
], | ||
}); | ||
`, | ||
"app/routes/pass-non-remix-exports-in-mdx.mdx": String.raw` | ||
// Remix exports | ||
export const ErrorBoundary = () => {} | ||
export const action = () => {} | ||
export const handle = () => {} | ||
export const headers = () => {} | ||
export const links = () => {} | ||
export const loader = () => {} | ||
export const meta = () => {} | ||
export const shouldRevalidate = () => {} | ||
export default function() {} | ||
// Non-Remix exports | ||
export const invalid1 = 1; | ||
export const invalid2 = 2; | ||
# Hello World | ||
`, | ||
}); | ||
let [client, server] = viteBuild({ cwd }); | ||
expect(client.status).toBe(0); | ||
expect(server.status).toBe(0); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters