@@ -2,6 +2,7 @@ import fs from 'fs'
2
2
import _debug from 'debug'
3
3
import { parse , SFCBlock } from '@vue/compiler-sfc'
4
4
import { getDescriptor , setDescriptor } from './utils/descriptorCache'
5
+ import { getResolvedScript , setResolvedScript } from './script'
5
6
6
7
const debug = _debug ( 'vite:hmr' )
7
8
@@ -50,6 +51,11 @@ export async function handleHotUpdate(file: string, modules: any[]) {
50
51
}
51
52
52
53
if ( ! isEqualBlock ( descriptor . template , prevDescriptor . template ) ) {
54
+ // when a <script setup> component's template changes, it will need correct
55
+ // binding metadata. However, when reloading the template alone the binding
56
+ // metadata will not be available since the script part isn't loaded.
57
+ // in this case, reuse the compiled script from previous descriptor.
58
+ setResolvedScript ( descriptor , getResolvedScript ( prevDescriptor ) ! )
53
59
needRerender = true
54
60
}
55
61
@@ -75,13 +81,6 @@ export async function handleHotUpdate(file: string, modules: any[]) {
75
81
const prev = prevStyles [ i ]
76
82
const next = nextStyles [ i ]
77
83
if ( ! prev || ! isEqualBlock ( prev , next ) ) {
78
- // css modules update causes a reload because the $style object is changed
79
- // and it may be used in JS.
80
- // if (prev.module != null || next.module != null) {
81
- // return modules.filter(
82
- // (m) => !/type=/.test(m.id) || /type=script/.test(m.id)
83
- // )
84
- // }
85
84
didUpdateStyle = true
86
85
filteredModules . push ( modules . find ( ( m ) => m . id . includes ( `index=${ i } ` ) ) )
87
86
}
0 commit comments