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

[2.x] hmr bug: can't implement hmr for custom file type such as .mdx #1321

Closed
csr632 opened this issue Jan 3, 2021 · 2 comments
Closed

[2.x] hmr bug: can't implement hmr for custom file type such as .mdx #1321

csr632 opened this issue Jan 3, 2021 · 2 comments

Comments

@csr632
Copy link
Member

csr632 commented Jan 3, 2021

Describe the bug

I can't make hmr works with custom file type such as .mdx. It alway do full reload.

Reproduction

https://github.com/csr632/test-vite/tree/hmr-bug

vite serve and edit Doc.mdx. It alway do full reload.

After some debugging, I found out that the module graph is incorrect:
For a single .mdx module, vite creates two duplicate ModuleNode:
image

The ?import query cause duplicate ModuleNode. The query is added here:

url = markExplicitImport(url)

This line doesn't add ?import query to .vue file, that's why @vitejs/plugin-vue doesn't suffer from this bug.

The source code of vite-plugin-mdx is here

How to fix

I suggest we remove the vue in this line:

const knownJsSrcRE = /\.((j|t)sx?|mjs|vue)($|\?)/

This is the only place where vite is still coupling with vue, giving "privilege" to vue.

After we change this line, @vitejs/plugin-vue should also be suffering from this bug.

Then, if the bug is fixed for @vitejs/plugin-vue, we can be sure that no other file types will suffer from this bug.

@yyx990803 Could you change this line and fix the bug for @vitejs/plugin-vue?

System Info

  • required vite version: 2.0.0-beta.3
  • required Operating System: Ubuntu
  • required Node version: 12.13.0
@yyx990803
Copy link
Member

yyx990803 commented Jan 3, 2021

@csr632
Copy link
Member Author

csr632 commented Jan 4, 2021

https://vitejs.dev/config/#transforminclude

For reference: https://github.com/vuejs/vitepress/blob/master/src/node/plugin.ts

The transforminclude doesn't help. I have updated the reproduction: https://github.com/csr632/test-vite/tree/hmr-bug

Actually I don't think transforminclude is needed in this case because I explicitly import Doc from "./Doc.mdx". The ?import query already do the job of transforminclude.

@yyx990803 yyx990803 reopened this Jan 4, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants