From cd1149091f656411b099d08a36810e50027ebebb Mon Sep 17 00:00:00 2001 From: daiwei Date: Fri, 28 Mar 2025 10:01:22 +0800 Subject: [PATCH 1/3] fix(plugin-vue): also update prev cache if script changed --- packages/plugin-vue/src/handleHotUpdate.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/plugin-vue/src/handleHotUpdate.ts b/packages/plugin-vue/src/handleHotUpdate.ts index a5781a3e..d78082b5 100644 --- a/packages/plugin-vue/src/handleHotUpdate.ts +++ b/packages/plugin-vue/src/handleHotUpdate.ts @@ -156,7 +156,7 @@ export async function handleHotUpdate( if (didUpdateStyle) { updateType.push(`style`) } - if (updateType.length) { + if (updateType.length || scriptChanged) { if (file.endsWith('.vue')) { // invalidate the descriptor cache so that the next transform will // re-analyze the file and pick up the changes. From f0bab01daf7d7f9708f4a86f2870c1b6ddacf05b Mon Sep 17 00:00:00 2001 From: daiwei Date: Fri, 28 Mar 2025 11:09:06 +0800 Subject: [PATCH 2/3] test: add test --- playground/vue/Hmr.vue | 5 +++++ playground/vue/__tests__/vue.spec.ts | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/playground/vue/Hmr.vue b/playground/vue/Hmr.vue index 541929d4..07dda06b 100644 --- a/playground/vue/Hmr.vue +++ b/playground/vue/Hmr.vue @@ -3,6 +3,10 @@

Click the button then edit this message. The count should be preserved.

{{ number }} +
+ bar-title + {{ bar }} +
diff --git a/playground/vue/__tests__/vue.spec.ts b/playground/vue/__tests__/vue.spec.ts index 898d5123..6a17ba07 100644 --- a/playground/vue/__tests__/vue.spec.ts +++ b/playground/vue/__tests__/vue.spec.ts @@ -221,6 +221,24 @@ describe('hmr', () => { await untilUpdated(() => page.textContent('.hmr-number'), '200') }) + test('should reload when script changes after a rerender', async () => { + // rerender + editFile('Hmr.vue', (code) => code.replace('bar-title', 'bar-title1')) + await untilUpdated(() => page.textContent('h2.hmr'), 'bar-title1') + + // change 'bar' to 'updated', should reload + editFile('Hmr.vue', (code) => + code.replace(`let bar = 'bar'`, `let bar = 'updated'`), + ) + await untilUpdated(() => page.textContent('.hmr-bar'), 'updated') + + // change 'updated' to 'bar', should reload again not rerender + editFile('Hmr.vue', (code) => + code.replace(`let bar = 'updated'`, `let bar = 'bar'`), + ) + await untilUpdated(() => page.textContent('.hmr-bar'), 'bar') + }) + test('global hmr for some scenarios', async () => { editFile('Hmr.vue', (code) => code.replace('', ' \n' + ''), From 7f0c44bd60093f35da5b7f57994c17aef8120edd Mon Sep 17 00:00:00 2001 From: daiwei Date: Fri, 28 Mar 2025 11:11:41 +0800 Subject: [PATCH 3/3] test: fix selector --- playground/vue/__tests__/vue.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playground/vue/__tests__/vue.spec.ts b/playground/vue/__tests__/vue.spec.ts index 6a17ba07..c44d5cd2 100644 --- a/playground/vue/__tests__/vue.spec.ts +++ b/playground/vue/__tests__/vue.spec.ts @@ -224,7 +224,7 @@ describe('hmr', () => { test('should reload when script changes after a rerender', async () => { // rerender editFile('Hmr.vue', (code) => code.replace('bar-title', 'bar-title1')) - await untilUpdated(() => page.textContent('h2.hmr'), 'bar-title1') + await untilUpdated(() => page.textContent('.hmr-bar-text'), 'bar-title1') // change 'bar' to 'updated', should reload editFile('Hmr.vue', (code) =>