@@ -2,6 +2,7 @@ import fs from 'fs'
22import _debug from 'debug'
33import { parse , SFCBlock } from '@vue/compiler-sfc'
44import { getDescriptor , setDescriptor } from './utils/descriptorCache'
5+ import { getResolvedScript , setResolvedScript } from './script'
56
67const debug = _debug ( 'vite:hmr' )
78
@@ -50,6 +51,11 @@ export async function handleHotUpdate(file: string, modules: any[]) {
5051 }
5152
5253 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 ) ! )
5359 needRerender = true
5460 }
5561
@@ -75,13 +81,6 @@ export async function handleHotUpdate(file: string, modules: any[]) {
7581 const prev = prevStyles [ i ]
7682 const next = nextStyles [ i ]
7783 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- // }
8584 didUpdateStyle = true
8685 filteredModules . push ( modules . find ( ( m ) => m . id . includes ( `index=${ i } ` ) ) )
8786 }
0 commit comments