File tree 4 files changed +32
-2
lines changed
4 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -45,7 +45,8 @@ export async function handleHotUpdate(
45
45
} ) [ 0 ]
46
46
const templateModule = modules . find ( ( m ) => / t y p e = t e m p l a t e / . test ( m . url ) )
47
47
48
- if ( hasScriptChanged ( prevDescriptor , descriptor ) ) {
48
+ const scriptChanged = hasScriptChanged ( prevDescriptor , descriptor )
49
+ if ( scriptChanged ) {
49
50
let scriptModule : ModuleNode | undefined
50
51
if (
51
52
( descriptor . scriptSetup ?. lang && ! descriptor . scriptSetup . src ) ||
@@ -66,7 +67,7 @@ export async function handleHotUpdate(
66
67
// binding metadata. However, when reloading the template alone the binding
67
68
// metadata will not be available since the script part isn't loaded.
68
69
// in this case, reuse the compiled script from previous descriptor.
69
- if ( mainModule && ! affectedModules . has ( mainModule ) ) {
70
+ if ( ! scriptChanged ) {
70
71
setResolvedScript (
71
72
descriptor ,
72
73
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 5
5
<div class =" hmr-block" >
6
6
<Hmr />
7
7
</div >
8
+ <div class =" hmr-tsx-block" >
9
+ <HmrTsx />
10
+ </div >
8
11
<Syntax />
9
12
<PreProcessors />
10
13
<CssModules />
27
30
28
31
<script setup lang="ts">
29
32
import Hmr from ' ./Hmr.vue'
33
+ import HmrTsx from ' ./HmrTsx.vue'
30
34
import Syntax from ' ./Syntax.vue'
31
35
import PreProcessors from ' ./PreProcessors.vue'
32
36
import CssModules from ' ./CssModules.vue'
Original file line number Diff line number Diff line change @@ -191,6 +191,14 @@ describe('hmr', () => {
191
191
editFile ( 'Hmr.vue' , ( code ) => code . replace ( / < t e m p l a t e > .+ < \/ t e m p l a t e > / s, '' ) )
192
192
await untilUpdated ( ( ) => page . innerHTML ( '.hmr-block' ) , '<!---->' )
193
193
} )
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
+ } )
194
202
} )
195
203
196
204
describe ( 'src imports' , ( ) => {
You can’t perform that action at this time.
0 commit comments