Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(hmr): re-resolve script after type dep changed #446

Merged
merged 4 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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