Skip to content

Commit 65abce4

Browse files
committed
fix: improve handling of transformed content in hot updates for Vue files
1 parent 8897938 commit 65abce4

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

packages/plugin-vue/src/handleHotUpdate.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import fs from 'node:fs'
12
import _debug from 'debug'
23
import type { SFCBlock, SFCDescriptor } from 'vue/compiler-sfc'
34
import type { HmrContext, ModuleNode } from 'vite'
@@ -160,9 +161,18 @@ export async function handleHotUpdate(
160161
}
161162
if (updateType.length) {
162163
if (file.endsWith('.vue')) {
163-
// invalidate the descriptor cache so that the next transform will
164-
// re-analyze the file and pick up the changes.
165-
invalidateDescriptor(file)
164+
// If the descriptor was created from transformed content (e.g., by UnoCSS vue-scoped),
165+
// we should update the main cache with the transformed descriptor instead of invalidating it.
166+
// This ensures that subsequent style block requests get the correct transformed content.
167+
const isTransformedContent = content !== fs.readFileSync(file, 'utf-8')
168+
if (isTransformedContent) {
169+
// Use the descriptor created from transformed content
170+
cache.set(file, descriptor)
171+
} else {
172+
// invalidate the descriptor cache so that the next transform will
173+
// re-analyze the file and pick up the changes.
174+
invalidateDescriptor(file)
175+
}
166176
} else {
167177
// https://github.com/vuejs/vitepress/issues/3129
168178
// For non-vue files, e.g. .md files in VitePress, invalidating the

0 commit comments

Comments
 (0)