Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitda26e52

Browse files
committed
fix(hmr): should reload if relies file changed after re-render
ref:vitejs/vite-plugin-vue@62b17f3
1 parent0f2d3eb commitda26e52

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

‎src/core/index.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,12 @@ export const plugin = createUnplugin<Options | undefined, false>(
227227
vite:{
228228
api,
229229
handleHotUpdate(ctx){
230+
ctx.server.ws.send({
231+
type:'custom',
232+
event:'file-changed',
233+
data:{file:normalizePath(ctx.file)},
234+
})
235+
230236
if(options.value.compiler.invalidateTypeCache){
231237
options.value.compiler.invalidateTypeCache(ctx.file)
232238
}

‎src/core/main.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,19 @@ export async function transformMain(
149149
`_sfc_main.__hmrId =${JSON.stringify(descriptor.id)}`,
150150
`typeof __VUE_HMR_RUNTIME__ !== 'undefined' && `+
151151
`__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+
`})`,
152155
)
153156
// check if the template is the only thing that changed
154157
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+
)
156165
}
157166
output.push(
158167
`import.meta.hot.accept(mod => {`,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp