Skip to content

Commit 8f9c624

Browse files
authored
fix(hmr): re-resolve script after type dep changed (#446)
1 parent 82ae949 commit 8f9c624

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

packages/plugin-vue/src/index.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
getSrcDescriptor,
2020
getTempSrcDescriptor,
2121
} from './utils/descriptorCache'
22-
import { clearScriptCache, getResolvedScript, typeDepToSFCMap } from './script'
22+
import { clearScriptCache, resolveScript, typeDepToSFCMap } from './script'
2323
import { transformMain } from './main'
2424
import { handleHotUpdate, handleTypeDepChange } from './handleHotUpdate'
2525
import { transformTemplateAsModule } from './template'
@@ -300,7 +300,12 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin<Api> {
300300
let block: SFCBlock | null | undefined
301301
if (query.type === 'script') {
302302
// handle <script> + <script setup> merge via compileScript()
303-
block = getResolvedScript(descriptor, ssr)
303+
block = resolveScript(
304+
descriptor,
305+
options.value,
306+
ssr,
307+
customElementFilter.value(filename),
308+
)
304309
} else if (query.type === 'template') {
305310
block = descriptor.template!
306311
} else if (query.type === 'style') {

playground/vue/Main.vue

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
</div>
1111
<HmrCircularReference name="test" />
1212
<TypeProps msg="msg" bar="bar" :id="123" />
13+
<TypePropsTsx msg="msg" bar="bar" />
1314
<Syntax />
1415
<PreProcessors />
1516
<PreProcessorsHmr />
@@ -56,6 +57,7 @@ import WorkerTest from './worker.vue'
5657
import { ref } from 'vue'
5758
import Url from './Url.vue'
5859
import TypeProps from './TypeProps.vue'
60+
import TypePropsTsx from './TypePropsTsx.vue'
5961
import DefaultLangs from './DefaultLangs.vue'
6062
import PreCompiled from './pre-compiled/foo.vue'
6163
import PreCompiledExternalScoped from './pre-compiled/external-scoped.vue'

playground/vue/TypePropsTsx.vue

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<script setup lang="tsx">
2+
import type { Props } from './types'
3+
4+
const props = defineProps<Props & { bar: string }>()
5+
</script>
6+
7+
<template>
8+
<h2>Imported Type Props</h2>
9+
<pre class="type-props-tsx">{{ props }}</pre>
10+
</template>

playground/vue/__tests__/vue.spec.ts

+14
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,20 @@ describe('macro imported types', () => {
349349
),
350350
)
351351
})
352+
353+
test('should hmr with lang=tsx', async () => {
354+
editFile('types.ts', (code) => code.replace('msg: string', ''))
355+
await untilUpdated(
356+
() => page.textContent('.type-props-tsx'),
357+
JSON.stringify(
358+
{
359+
bar: 'bar',
360+
},
361+
null,
362+
2,
363+
),
364+
)
365+
})
352366
})
353367

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

0 commit comments

Comments
 (0)