File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -227,6 +227,12 @@ export const plugin = createUnplugin<Options | undefined, false>(
227
227
vite : {
228
228
api,
229
229
handleHotUpdate ( ctx ) {
230
+ ctx . server . ws . send ( {
231
+ type : 'custom' ,
232
+ event : 'file-changed' ,
233
+ data : { file : normalizePath ( ctx . file ) } ,
234
+ } )
235
+
230
236
if ( options . value . compiler . invalidateTypeCache ) {
231
237
options . value . compiler . invalidateTypeCache ( ctx . file )
232
238
}
Original file line number Diff line number Diff line change @@ -149,10 +149,19 @@ export async function transformMain(
149
149
`_sfc_main.__hmrId = ${ JSON . stringify ( descriptor . id ) } ` ,
150
150
`typeof __VUE_HMR_RUNTIME__ !== 'undefined' && ` +
151
151
`__VUE_HMR_RUNTIME__.createRecord(_sfc_main.__hmrId, _sfc_main)` ,
152
+ `import.meta.hot.on('file-changed', ({ file }) => {` ,
153
+ ` __VUE_HMR_RUNTIME__.CHANGED_FILE = file` ,
154
+ `})` ,
152
155
)
153
156
// check if the template is the only thing that changed
154
157
if ( prevDescriptor && isOnlyTemplateChanged ( prevDescriptor , descriptor ) ) {
155
- output . push ( `export const _rerender_only = true` )
158
+ // #7 only consider re-render if the HMR is triggered by the current component,
159
+ // otherwise reload. Due to vite will cache the transform result. If the HMR
160
+ // is triggered by other files that the current component relies on, a reload
161
+ // is required.
162
+ output . push (
163
+ `export const _rerender_only = __VUE_HMR_RUNTIME__.CHANGED_FILE === ${ JSON . stringify ( normalizePath ( filename ) ) } ` ,
164
+ )
156
165
}
157
166
output . push (
158
167
`import.meta.hot.accept(mod => {` ,
You can’t perform that action at this time.
0 commit comments