Skip to content

Commit

Permalink
fix(hmr): re-resolve script after type dep changed (#446)
Browse files Browse the repository at this point in the history
  • Loading branch information
edison1105 authored Nov 11, 2024
1 parent 82ae949 commit 8f9c624
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/plugin-vue/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
getSrcDescriptor,
getTempSrcDescriptor,
} from './utils/descriptorCache'
import { clearScriptCache, getResolvedScript, typeDepToSFCMap } from './script'
import { clearScriptCache, resolveScript, typeDepToSFCMap } from './script'
import { transformMain } from './main'
import { handleHotUpdate, handleTypeDepChange } from './handleHotUpdate'
import { transformTemplateAsModule } from './template'
Expand Down Expand Up @@ -300,7 +300,12 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin<Api> {
let block: SFCBlock | null | undefined
if (query.type === 'script') {
// handle <script> + <script setup> merge via compileScript()
block = getResolvedScript(descriptor, ssr)
block = resolveScript(
descriptor,
options.value,
ssr,
customElementFilter.value(filename),
)
} else if (query.type === 'template') {
block = descriptor.template!
} else if (query.type === 'style') {
Expand Down
2 changes: 2 additions & 0 deletions playground/vue/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</div>
<HmrCircularReference name="test" />
<TypeProps msg="msg" bar="bar" :id="123" />
<TypePropsTsx msg="msg" bar="bar" />
<Syntax />
<PreProcessors />
<PreProcessorsHmr />
Expand Down Expand Up @@ -56,6 +57,7 @@ import WorkerTest from './worker.vue'
import { ref } from 'vue'
import Url from './Url.vue'
import TypeProps from './TypeProps.vue'
import TypePropsTsx from './TypePropsTsx.vue'
import DefaultLangs from './DefaultLangs.vue'
import PreCompiled from './pre-compiled/foo.vue'
import PreCompiledExternalScoped from './pre-compiled/external-scoped.vue'
Expand Down
10 changes: 10 additions & 0 deletions playground/vue/TypePropsTsx.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script setup lang="tsx">
import type { Props } from './types'
const props = defineProps<Props & { bar: string }>()
</script>

<template>
<h2>Imported Type Props</h2>
<pre class="type-props-tsx">{{ props }}</pre>
</template>
14 changes: 14 additions & 0 deletions playground/vue/__tests__/vue.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,20 @@ describe('macro imported types', () => {
),
)
})

test('should hmr with lang=tsx', async () => {
editFile('types.ts', (code) => code.replace('msg: string', ''))
await untilUpdated(
() => page.textContent('.type-props-tsx'),
JSON.stringify(
{
bar: 'bar',
},
null,
2,
),
)
})
})

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

0 comments on commit 8f9c624

Please sign in to comment.