HMR throws error when SFC contains style
tag injected by plugin
#301
Labels
p2-nice-to-have 🍰
Not breaking anything but nice to have (priority)
Related plugins
plugin-vue
plugin-vue-jsx
Describe the bug
In the provided reproduction, the SFC should contain two
<style>
tags: the first one is written explicitly in the file, the second one is appended to the end of the file intransform
/handleHotUpdate
hooksThe error appears when
handleHotUpdate
is called, the cached file descriptor is invalidated:vite-plugin-vue/packages/plugin-vue/src/handleHotUpdate.ts
Lines 158 to 161 in 66d81ce
vite-plugin-vue/packages/plugin-vue/src/handleHotUpdate.ts
Lines 163 to 170 in 66d81ce
So basically, after invalidation, the
load()
hook reads file source without any plugin transformations. And if the file contains twostyle
tags, as in the reproduction (one of them in injected intransform
), thengetDescriptor
caches the file without secondstyle
.It's very similar to vuejs/vitepress#3129, however in that case it was about
.md
files and a26a854 fixed it perfectlyThe
unocss
uses this trick to inject resolved classes to the<style scoped>
https://github.com/unocss/unocss/blob/6aa1578976c902b315dd500a533a088456de67d8/packages/vite/src/modes/vue-scoped.ts#L28-L41
Related: unocss/unocss#3358
Reproduction
https://stackblitz.com/edit/vitejs-vite-n7dupt?file=src%2FApp.vue
Steps to reproduce
src/App.vue
System Info
Used Package Manager
npm
Logs
Click to expand!
Validations
The text was updated successfully, but these errors were encountered: