Skip to content

fix(plugin-vue): also update prev cache if script changed #557

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion packages/plugin-vue/src/handleHotUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions playground/vue/Hmr.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
<p>Click the button then edit this message. The count should be preserved.</p>
<button class="hmr-inc" @click="count++">count is {{ count }}</button>
<span class="hmr-number">{{ number }}</span>
<div>
<span class="hmr-bar-text">bar-title</span>
<span class="hmr-bar">{{ bar }}</span>
</div>
</template>

<script setup lang="ts">
Expand All @@ -12,6 +16,7 @@ import { test } from './lib.js'
const number = test()

let foo: number = 0
let bar = 'bar'

const count = ref(foo)
</script>
Expand Down
18 changes: 18 additions & 0 deletions playground/vue/__tests__/vue.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('.hmr-bar-text'), '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('</template>', ' <Node/>\n' + '</template>'),
Expand Down