Skip to content

Commit 9c74982

Browse files
committed
fix(plugin-vue): ensure HMR updates styles when SFC is treated as a type dependency
1 parent 59946d3 commit 9c74982

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed

packages/plugin-vue/src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,12 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin<Api> {
224224
if (options.value.compiler.invalidateTypeCache) {
225225
options.value.compiler.invalidateTypeCache(ctx.file)
226226
}
227+
const matchesFilter = filter.value(ctx.file)
227228
if (typeDepToSFCMap.has(ctx.file)) {
228-
return handleTypeDepChange(typeDepToSFCMap.get(ctx.file)!, ctx)
229+
const mod = handleTypeDepChange(typeDepToSFCMap.get(ctx.file)!, ctx)
230+
if (!matchesFilter) return mod
229231
}
230-
if (filter.value(ctx.file)) {
232+
if (matchesFilter) {
231233
return handleHotUpdate(
232234
ctx,
233235
options.value,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<template>
2+
<div class="export-type-props1">foo: {{ title }}</div>
3+
</template>
4+
5+
<script lang="ts">
6+
export interface FooProps {
7+
title?: string
8+
}
9+
</script>
10+
11+
<script setup lang="ts">
12+
defineProps<FooProps>()
13+
</script>
14+
15+
<style>
16+
.export-type-props1 {
17+
color: red;
18+
}
19+
</style>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script setup lang="ts">
2+
import type { FooProps } from './ExportTypeProps1.vue'
3+
defineProps<FooProps>()
4+
</script>
5+
6+
<template>
7+
<div>bar: {{ title }}</div>
8+
</template>

playground/vue/Main.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
<PreCompiledExternalScoped />
3737
<PreCompiledExternalCssModules />
3838
<ParserOptions />
39+
<ExportTypeProps1 />
40+
<ExportTypeProps2 />
3941
</template>
4042

4143
<script setup lang="ts">
@@ -66,6 +68,8 @@ import PreCompiledExternalScoped from './pre-compiled/external-scoped.vue'
6668
import PreCompiledExternalCssModules from './pre-compiled/external-cssmodules.vue'
6769
import ParserOptions from './ParserOptions.vue'
6870
import HmrCircularReference from './HmrCircularReference.vue'
71+
import ExportTypeProps1 from './ExportTypeProps1.vue'
72+
import ExportTypeProps2 from './ExportTypeProps2.vue'
6973
7074
const TsGeneric = defineAsyncComponent(() => import('./TsGeneric.vue'))
7175

playground/vue/__tests__/vue.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,13 @@ describe('macro imported types', () => {
409409
),
410410
)
411411
})
412+
413+
test('should update style', async () => {
414+
const cls = '.export-type-props1'
415+
expect(await getColor(cls)).toBe('red')
416+
editFile('ExportTypeProps1.vue', (code) => code.replace('red', 'blue'))
417+
await untilUpdated(() => getColor(cls), 'blue')
418+
})
412419
})
413420

414421
test('TS with generics', async () => {

0 commit comments

Comments
 (0)