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

feat(remix-dev/vite): support HMR for MDX #7954

Closed
wants to merge 2 commits into from
Closed
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/four-bottles-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/dev": patch
---

feat: support HMR for MDX
21 changes: 21 additions & 0 deletions integration/vite-dev-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ test.describe("Vite dev", () => {
## MDX Route

<MdxComponent />

### HMR updated: no

<input />
`,
},
});
Expand Down Expand Up @@ -297,6 +301,23 @@ test.describe("Vite dev", () => {
let mdxContent = page.locator("[data-mdx-route]");
await expect(mdxContent).toHaveText("MDX route content from loader");

// verify HMR
let hmrStatus = page.locator("h3");
await expect(hmrStatus).toHaveText("HMR updated: no");

let input = page.locator("input");
await input.type("stateful");

let filepath = path.join(projectDir, "app/routes/mdx.mdx");
let src = await fs.readFile(filepath, "utf8");
await fs.writeFile(
filepath,
src.replace("HMR updated: no", "HMR updated: yes"),
"utf8"
);
await expect(hmrStatus).toHaveText("HMR updated: yes");
await expect(input).toHaveValue("stateful");

expect(pageErrors).toEqual([]);
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/remix-dev/vite/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ export const remixVitePlugin: RemixVitePlugin = (options = {}) => {
if (id.includes("/node_modules/")) return;

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

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