Skip to content

Commit

Permalink
add jsxDev flag, add changeset
Browse files Browse the repository at this point in the history
  • Loading branch information
markdalgleish committed Nov 3, 2023
1 parent ceeb3fd commit 7aae9b1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/clever-months-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/dev": patch
---

Support JSX usage in `.jsx` files without manual `React` import in Vite
19 changes: 10 additions & 9 deletions integration/vite-dev-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ test.describe("Vite dev", () => {
);
}
`,
"app/routes/non-ts.jsx": js`
export default function Page() {
"app/routes/jsx.jsx": js`
export default function JsxRoute() {
return (
<div id="non-ts">
<div id="jsx">
<p data-hmr>HMR updated: no</p>
</div>
);
Expand Down Expand Up @@ -238,31 +238,32 @@ test.describe("Vite dev", () => {
);
});

test("handle non-typescript jsx file", async ({ page }) => {
test("handles JSX in .jsx file without React import", async ({ page }) => {
let pageErrors: unknown[] = [];
page.on("pageerror", (error) => pageErrors.push(error));

await page.goto(`http://localhost:${devPort}/non-ts`, {
await page.goto(`http://localhost:${devPort}/jsx`, {
waitUntil: "networkidle",
});
expect(pageErrors).toEqual([]);

let hmrStatus = page.locator("#non-ts [data-hmr]");
let hmrStatus = page.locator("#jsx [data-hmr]");
await expect(hmrStatus).toHaveText("HMR updated: no");

let indexRouteContents = await fs.readFile(
path.join(projectDir, "app/routes/non-ts.jsx"),
path.join(projectDir, "app/routes/jsx.jsx"),
"utf8"
);
await fs.writeFile(
path.join(projectDir, "app/routes/non-ts.jsx"),
path.join(projectDir, "app/routes/jsx.jsx"),
indexRouteContents.replace("HMR updated: no", "HMR updated: yes"),
"utf8"
);
await page.waitForLoadState("networkidle");
await expect(hmrStatus).toHaveText("HMR updated: yes");

expect(pageErrors).toEqual([]);
})
});
});

let bufferize = (stream: Readable): (() => string) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/remix-dev/vite/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,9 @@ export const remixVitePlugin: RemixVitePlugin = (options = {}) => {
"react-dom/client",
],
},
// for server module, JSX transpilation is done by vite's esbuild
esbuild: {
jsx: 'automatic',
jsx: "automatic",
jsxDev: viteCommand !== "build",
},
resolve: {
// https://react.dev/warnings/invalid-hook-call-warning#duplicate-react
Expand Down

0 comments on commit 7aae9b1

Please sign in to comment.