You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 in transform/handleHotUpdate hooks
The error appears when handleHotUpdate is called, the cached file descriptor is invalidated:
// For non-vue files, e.g. .md files in VitePress, invalidating the
// descriptor will cause the main `load()` hook to attempt to read and
// parse a descriptor from a non-vue source file, leading to errors.
// To fix that we need to provide the descriptor we parsed here in the
// main cache. This assumes no other plugin is applying pre-transform to
// the file type - not impossible, but should be extremely unlikely.
cache.set(file,descriptor)
So basically, after invalidation, the load() hook reads file source without any plugin transformations. And if the file contains two style tags, as in the reproduction (one of them in injected in transform), then getDescriptor caches the file without second style.
It's very similar to vuejs/vitepress#3129, however in that case it was about .md files and a26a854 fixed it perfectly
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
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: