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): correct hmr for sfc has setup script when it template change #763

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
12 changes: 12 additions & 0 deletions playground/script-setup/TestScriptSetupChild.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<template>
<h2>The hmr should work with setup script block w/ template block has child component</h2>
<p class="test-script-setup-child">Child has prop {{msg}}</p>
</template>

<script>
export default {
props: {
msg: String
}
}
</script>
3 changes: 3 additions & 0 deletions playground/script-setup/TestScriptSetupStyleVars.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
<span class="style-vars">This should be red</span>
<button class="script-setup-change" @click="change">click to change</button>
</p>
<TestScriptSetupChild msg="hello"/>
</template>

<script setup>
import { ref } from 'vue'
export { default as TestScriptSetupChild } from './TestScriptSetupChild.vue'

export default {
props: {
Expand All @@ -21,6 +23,7 @@ export const color = ref('red')
export function change() {
color.value = color.value === 'red' ? 'green' : 'red'
}

</script>

<style scoped vars="{ color }">
Expand Down
4 changes: 4 additions & 0 deletions src/node/server/serverPluginVue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ export const vuePlugin: ServerPlugin = ({
}

if (!isEqualBlock(descriptor.template, prevDescriptor.template)) {
// #748 should re-use previous cached script if only template change
if (prevDescriptor.scriptSetup && descriptor.scriptSetup) {
vueCache.get(filePath)!.script = cacheEntry!.script
}
needRerender = true
}

Expand Down
8 changes: 8 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,14 @@ describe('vite', () => {
() => getComputedColor(`.style-vars`),
'rgb(0, 0, 255)'
)
// #748
await updateFile('script-setup/TestScriptSetupStyleVars.vue', (c) =>
c.replace(`msg="hello"`, `msg="hi"`)
)
await expectByPolling(
() => getText('.test-script-setup-child'),
'Child has prop hi'
)
}
})

Expand Down