-
-
Notifications
You must be signed in to change notification settings - Fork 153
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
HMR always reloading script in SFC when just style is changed if using another vite plugin that transforms the script #211
Comments
I found a solution and will submit a PR soon. |
I sketched out two different solutions: [A] Transform original source with preceding pluginsCode [B] Save original source on our
|
Fixed by #227 |
Related plugins
plugin-vue
plugin-vue-jsx
Describe the bug
When using another vite plugin like @vue-macros/reactivity-transform that transforms the source code, HMR will always update the script part of an SFC even if it's not changed, for example when editing just css. This leads to the whole script being executed again and state being lost.
When changing css I expect this in the console:
but with another plugin present I get:
This most likely happens because handleHotUpdate reads the raw file, parses it, and compares it with the previous version from the cache populated by transformMain, which gets the already transformed code directly from vite. Since the untransformed and transformed source is always different, even if no edits happen, vite-plugin-vue assumes an edit happened and adds the script to the list of affected modules.
I looked a bit into a solution, but neither always caching with the raw source nor always transforming seems straight forward.
Applying the same plugins to the source in the
handleHotUpdate
hook so it's based on the same code that thetransform
hook gets is probably preferable, but I couldn't find anything to do that in the vite API.Reproduction
https://stackblitz.com/edit/vitejs-vite-tzll9a?file=src%2FApp.vue&terminal=dev
Steps to reproduce
App.vue
System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: