|
| 1 | +import fs from 'node:fs' |
1 | 2 | import _debug from 'debug' |
2 | 3 | import type { SFCBlock, SFCDescriptor } from 'vue/compiler-sfc' |
3 | 4 | import type { HmrContext, ModuleNode } from 'vite' |
@@ -160,9 +161,18 @@ export async function handleHotUpdate( |
160 | 161 | } |
161 | 162 | if (updateType.length) { |
162 | 163 | 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 | + } |
166 | 176 | } else { |
167 | 177 | // https://github.com/vuejs/vitepress/issues/3129 |
168 | 178 | // For non-vue files, e.g. .md files in VitePress, invalidating the |
|
0 commit comments