mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix(nuxt): do not rerun synchronous callOnce
callbacks (#25431)
This commit is contained in:
parent
3f51277219
commit
aa4faaab3c
@ -25,7 +25,7 @@ export async function callOnce (...args: any): Promise<void> {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
nuxtApp._once = nuxtApp._once || {}
|
nuxtApp._once = nuxtApp._once || {}
|
||||||
nuxtApp._once[_key] = nuxtApp._once[_key] || fn()
|
nuxtApp._once[_key] = nuxtApp._once[_key] || fn() || true
|
||||||
await nuxtApp._once[_key]
|
await nuxtApp._once[_key]
|
||||||
nuxtApp.payload.once.add(_key)
|
nuxtApp.payload.once.add(_key)
|
||||||
delete nuxtApp._once[_key]
|
delete nuxtApp._once[_key]
|
||||||
|
@ -595,6 +595,11 @@ describe('callOnce', () => {
|
|||||||
const execute = () => callOnce(fn)
|
const execute = () => callOnce(fn)
|
||||||
await Promise.all([execute(), execute(), execute()])
|
await Promise.all([execute(), execute(), execute()])
|
||||||
expect(fn).toHaveBeenCalledTimes(1)
|
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 () => {
|
it('should use key to dedupe', async () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user