diff --git a/packages/nuxt/src/app/composables/once.ts b/packages/nuxt/src/app/composables/once.ts index c8c664826d..177ab4c9d5 100644 --- a/packages/nuxt/src/app/composables/once.ts +++ b/packages/nuxt/src/app/composables/once.ts @@ -25,7 +25,7 @@ export async function callOnce (...args: any): Promise { return } nuxtApp._once = nuxtApp._once || {} - nuxtApp._once[_key] = nuxtApp._once[_key] || fn() + nuxtApp._once[_key] = nuxtApp._once[_key] || fn() || true await nuxtApp._once[_key] nuxtApp.payload.once.add(_key) delete nuxtApp._once[_key] diff --git a/test/nuxt/composables.test.ts b/test/nuxt/composables.test.ts index f9229a01d2..ee96662c91 100644 --- a/test/nuxt/composables.test.ts +++ b/test/nuxt/composables.test.ts @@ -595,6 +595,11 @@ describe('callOnce', () => { const execute = () => callOnce(fn) await Promise.all([execute(), execute(), execute()]) expect(fn).toHaveBeenCalledTimes(1) + + const fnSync = vi.fn().mockImplementation(() => { }) + const executeSync = () => callOnce(fnSync) + await Promise.all([executeSync(), executeSync(), executeSync()]) + expect(fnSync).toHaveBeenCalledTimes(1) }) it('should use key to dedupe', async () => {