File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -45,7 +45,8 @@ export async function handleHotUpdate(
4545 } ) [ 0 ]
4646 const templateModule = modules . find ( ( m ) => / t y p e = t e m p l a t e / . test ( m . url ) )
4747
48- if ( hasScriptChanged ( prevDescriptor , descriptor ) ) {
48+ const scriptChanged = hasScriptChanged ( prevDescriptor , descriptor )
49+ if ( scriptChanged ) {
4950 let scriptModule : ModuleNode | undefined
5051 if (
5152 ( descriptor . scriptSetup ?. lang && ! descriptor . scriptSetup . src ) ||
@@ -66,7 +67,7 @@ export async function handleHotUpdate(
6667 // binding metadata. However, when reloading the template alone the binding
6768 // metadata will not be available since the script part isn't loaded.
6869 // in this case, reuse the compiled script from previous descriptor.
69- if ( mainModule && ! affectedModules . has ( mainModule ) ) {
70+ if ( ! scriptChanged ) {
7071 setResolvedScript (
7172 descriptor ,
7273 getResolvedScript ( prevDescriptor , false ) ! ,
Original file line number Diff line number Diff line change 1+ <template >
2+ <h2 class =" hmr-tsx" >HMR</h2 >
3+ <p >Click the button then edit this message. The count should be preserved.</p >
4+ <button class =" hmr-tsx-inc" @click =" count++" >count is {{ count }}</button >
5+ </template >
6+
7+ <script setup lang="tsx">
8+ import { ref } from ' vue'
9+
10+ const count = ref (0 )
11+ </script >
12+
13+ <style >
14+ .hmr-tsx-inc {
15+ color : red ;
16+ }
17+ </style >
Original file line number Diff line number Diff line change 55 <div class =" hmr-block" >
66 <Hmr />
77 </div >
8+ <div class =" hmr-tsx-block" >
9+ <HmrTsx />
10+ </div >
811 <Syntax />
912 <PreProcessors />
1013 <CssModules />
2730
2831<script setup lang="ts">
2932import Hmr from ' ./Hmr.vue'
33+ import HmrTsx from ' ./HmrTsx.vue'
3034import Syntax from ' ./Syntax.vue'
3135import PreProcessors from ' ./PreProcessors.vue'
3236import CssModules from ' ./CssModules.vue'
Original file line number Diff line number Diff line change @@ -191,6 +191,14 @@ describe('hmr', () => {
191191 editFile ( 'Hmr.vue' , ( code ) => code . replace ( / < t e m p l a t e > .+ < \/ t e m p l a t e > / s, '' ) )
192192 await untilUpdated ( ( ) => page . innerHTML ( '.hmr-block' ) , '<!---->' )
193193 } )
194+
195+ test ( 'should re-render when template and tsx script both changed' , async ( ) => {
196+ editFile ( 'HmrTsx.vue' , ( code ) => code . replace ( / c o u n t / g, 'updatedCount' ) )
197+ await untilUpdated (
198+ ( ) => page . innerHTML ( '.hmr-tsx-block .hmr-tsx-inc' ) ,
199+ 'updatedCount is 0'
200+ )
201+ } )
194202} )
195203
196204describe ( 'src imports' , ( ) => {
You can’t perform that action at this time.
0 commit comments