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
/nuxtPublic

Commitfe7e3ce

Browse files
huang-juliendanielroe
authored andcommitted
fix(nuxt): re-executecallOnce during HMR (#33810)
1 parent0994403 commitfe7e3ce

File tree

1 file changed

+20
-1
lines changed
  • packages/nuxt/src/app/composables

1 file changed

+20
-1
lines changed

‎packages/nuxt/src/app/composables/once.ts‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ type CallOnceOptions = {
55
mode?:'navigation'|'render'
66
}
77

8+
let_isHmrUpdating=false
9+
810
/**
911
* An SSR-friendly utility to call a method once
1012
*@param key a unique key ensuring the function can be properly de-duplicated across requests
@@ -40,7 +42,10 @@ export async function callOnce (...args: any): Promise<void> {
4042

4143
// If key already ran
4244
if(nuxtApp.payload.once.has(_key)){
43-
return
45+
// Allow re-execution during HMR
46+
if(!import.meta.dev||!_isHmrUpdating){
47+
return
48+
}
4449
}
4550

4651
nuxtApp._once||={}
@@ -49,3 +54,17 @@ export async function callOnce (...args: any): Promise<void> {
4954
nuxtApp.payload.once.add(_key)
5055
deletenuxtApp._once[_key]
5156
}
57+
58+
if(import.meta.hot){
59+
import.meta.hot.on('vite:beforeUpdate',(payload)=>{
60+
if(payload.updates.some((u:any)=>u.type==='js-update')){
61+
_isHmrUpdating=true
62+
}
63+
})
64+
65+
import.meta.hot.on('vite:afterUpdate',(payload)=>{
66+
if(payload.updates.some((u:any)=>u.type==='js-update')){
67+
_isHmrUpdating=false
68+
}
69+
})
70+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp