@@ -5,6 +5,8 @@ type CallOnceOptions = {
55mode ?:'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
4244if ( nuxtApp . payload . once . has ( _key ) ) {
43- return
45+ // Allow re-execution during HMR
46+ if ( ! import . meta. dev || ! _isHmrUpdating ) {
47+ return
48+ }
4449}
4550
4651nuxtApp . _once ||= { }
@@ -49,3 +54,17 @@ export async function callOnce (...args: any): Promise<void> {
4954nuxtApp . payload . once . add ( _key )
5055delete nuxtApp . _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+ }