Skip to content

Conversation

@kenn
Copy link
Contributor

@kenn kenn commented Dec 29, 2025

Summary

  • exclude .md/.mdx files from dev-server request handling so they pass through Vite
  • prevent MDX routes from being treated as HTTP requests by the server adapter

Motivation

Using @mdx-js/rollup with @hono/vite-dev-server causes .mdx files to be intercepted by the dev server and treated as HTTP routes (e.g. No route matches URL "/app/routes/privacy.mdx").

This happens because the default exclude list does not include Markdown/MDX files.

Adding .mdx? avoids the interception and lets Vite handle transforms as intended.

Current Workaround

Users must override the entire exclude list to add MDX support (for a React Router v7 app):

export default defineConfig({
  plugins: [
    serverAdapter({
      entry: 'server/index.ts',
      exclude: [/^\/app\//, /^\/@/, /^\/node_modules\//], // add this line
    })
    mdx(), // must come before reactRouter
    reactRouter(),
    ...

This is error-prone because:

  1. The default array isn’t merged (uses ??, not a spread/concat).
  2. Users may miss important patterns
  3. The workaround isn't documented

Alternatively, we could add a safe way to extend the default excludes, but that would be a lot more work. Supporting .md/.mdx covers a large share of common use cases.

@changeset-bot
Copy link

changeset-bot bot commented Dec 29, 2025

🦋 Changeset detected

Latest commit: 1a0233a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@hono/vite-dev-server Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@yusukebe
Copy link
Member

Hi @kenn

Thank you for the PR. I think this is good. One thing. Can you add a changeset file by running yarn changeset at the top of the project? This is a slight change, but introducing a new feature, so a minor change is okay.

@kenn
Copy link
Contributor Author

kenn commented Dec 30, 2025

Thanks @yusukebe, done!

@yusukebe yusukebe changed the title Add .md/.mdx to defaultOptions.exclude feat(dev-server): Add .md/.mdx to defaultOptions.exclude Dec 30, 2025
@yusukebe
Copy link
Member

Thank you @kenn ! I'll merge.

@yusukebe yusukebe merged commit 041fd21 into honojs:main Dec 30, 2025
4 checks passed
@github-actions github-actions bot mentioned this pull request Dec 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants