Skip to content
Open
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/cold-bulldogs-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@react-router/dev": patch
---

fix: add support for `.md` and `.mdx` file modules in type generation
32 changes: 32 additions & 0 deletions integration/typegen-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -743,4 +743,36 @@ test.describe("typegen", () => {
expect(proc.stderr.toString()).toBe("");
expect(proc.status).toBe(0);
});

test("md/mdx route", async () => {
const cwd = await createProject({
"vite.config.ts": tsx`
import mdx from "@mdx-js/rollup";
import { reactRouter } from "@react-router/dev/vite";

export default {
plugins: [mdx(), reactRouter()],
};
`,
"app/routes.ts": tsx`
import { type RouteConfig, route } from "@react-router/dev/routes";

export default [
route("home", "routes/home.md"),
route("changelog", "routes/changelog.mdx"),
] satisfies RouteConfig;
`,
"app/routes/home.md": tsx`
# Lorem ipsum
`,
"app/routes/changelog.mdx": tsx`
# Lorem ipsum
`,
});

const proc = typecheck(cwd);
expect(proc.stdout.toString()).toBe("");
expect(proc.stderr.toString()).toBe("");
expect(proc.status).toBe(0);
});
});
12 changes: 12 additions & 0 deletions packages/react-router-dev/typegen/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ export function generateServerBuild(ctx: Context): VirtualFile {
export const ssr: ServerBuild["ssr"];
export const unstable_getCriticalCss: ServerBuild["unstable_getCriticalCss"];
}

declare module "*.md" {
import * as React from "react";
const MDComponent: React.FunctionComponent<any>;
export default MDComponent;
}

declare module "*.mdx" {
import * as React from "react";
const MDXComponent: React.FunctionComponent<any>;
export default MDXComponent;
}
`;
return { filename, content };
}
Expand Down
Loading