From 9d0b9d834bd4fe0b16d18eeb7af10742c278673b Mon Sep 17 00:00:00 2001 From: sun0day Date: Fri, 25 Nov 2022 23:53:50 +0800 Subject: [PATCH] fix(plugin-vue): invalidate script module cache when it changed in hot update (#11059) --- packages/plugin-vue/src/handleHotUpdate.ts | 5 +++-- playground/vue/HmrTsx.vue | 17 +++++++++++++++++ playground/vue/Main.vue | 4 ++++ playground/vue/__tests__/vue.spec.ts | 8 ++++++++ 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 playground/vue/HmrTsx.vue diff --git a/packages/plugin-vue/src/handleHotUpdate.ts b/packages/plugin-vue/src/handleHotUpdate.ts index 5569f0dfbe02ae..d1dde364eb7f10 100644 --- a/packages/plugin-vue/src/handleHotUpdate.ts +++ b/packages/plugin-vue/src/handleHotUpdate.ts @@ -45,7 +45,8 @@ export async function handleHotUpdate( })[0] const templateModule = modules.find((m) => /type=template/.test(m.url)) - if (hasScriptChanged(prevDescriptor, descriptor)) { + const scriptChanged = hasScriptChanged(prevDescriptor, descriptor) + if (scriptChanged) { let scriptModule: ModuleNode | undefined if ( (descriptor.scriptSetup?.lang && !descriptor.scriptSetup.src) || @@ -66,7 +67,7 @@ export async function handleHotUpdate( // binding metadata. However, when reloading the template alone the binding // metadata will not be available since the script part isn't loaded. // in this case, reuse the compiled script from previous descriptor. - if (mainModule && !affectedModules.has(mainModule)) { + if (!scriptChanged) { setResolvedScript( descriptor, getResolvedScript(prevDescriptor, false)!, diff --git a/playground/vue/HmrTsx.vue b/playground/vue/HmrTsx.vue new file mode 100644 index 00000000000000..c1a2331da6a6be --- /dev/null +++ b/playground/vue/HmrTsx.vue @@ -0,0 +1,17 @@ + + + + + diff --git a/playground/vue/Main.vue b/playground/vue/Main.vue index 521bbbff08a3ce..b91d50f9287a31 100644 --- a/playground/vue/Main.vue +++ b/playground/vue/Main.vue @@ -5,6 +5,9 @@
+
+ +
@@ -27,6 +30,7 @@