Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wet-bulldogs-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/dev": patch
---

Vite: Enable HMR for .md and .mdx files
55 changes: 55 additions & 0 deletions integration/vite-hmr-hdr-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,61 @@ test("Vite / HMR & HDR / express", async ({ page, browserName, customDev }) => {
await workflow({ page, browserName, cwd, port });
});

test("Vite / HMR & HDR / mdx", async ({ page, viteDev }) => {
let files: Files = async ({ port }) => ({
"vite.config.ts": `
import { defineConfig } from "vite";
import { unstable_vitePlugin as remix } from "@remix-run/dev";
import mdx from "@mdx-js/rollup";

export default defineConfig({
${await viteConfig.server({ port })}
plugins: [
mdx(),
remix(),
],
});
`,
"app/component.tsx": `
import {useState} from "react";

export const Counter = () => {
const [count, setCount] = useState(0);
return <button onClick={() => setCount(count => count + 1)}>Count: {count}</button>
}
`,
"app/routes/mdx.mdx": `
import { Counter } from "../component";

# MDX Title (HMR: 0)

<Counter />
`,
});

let { port, cwd } = await viteDev(files);
let edit = createEditor(cwd);
await page.goto(`http://localhost:${port}/mdx`, {
waitUntil: "networkidle",
});

await expect(page.locator("h1")).toHaveText("MDX Title (HMR: 0)");
let button = page.locator("button");
await expect(button).toHaveText("Count: 0");
await button.click();
await expect(button).toHaveText("Count: 1");

await edit("app/routes/mdx.mdx", (contents) =>
contents.replace("(HMR: 0)", "(HMR: 1)")
);
await page.waitForLoadState("networkidle");

await expect(page.locator("h1")).toHaveText("MDX Title (HMR: 1)");
await expect(page.locator("button")).toHaveText("Count: 1");

expect(page.errors).toEqual([]);
});

async function workflow({
page,
browserName,
Expand Down
3 changes: 2 additions & 1 deletion packages/remix-dev/vite/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1491,7 +1491,8 @@ export const remixVitePlugin: RemixVitePlugin = (remixUserConfig = {}) => {
if (id.includes("/node_modules/")) return;

let [filepath] = id.split("?");
if (!/.[tj]sx?$/.test(filepath)) return;
let extensionsRE = /\.(jsx?|tsx?|mdx?)$/;
if (!extensionsRE.test(filepath)) return;

let devRuntime = "react/jsx-dev-runtime";
let ssr = options?.ssr === true;
Expand Down