fix(nuxt): await nuxt ready state before refreshNuxtData (#21008)

This commit is contained in:
Lucie 2023-05-23 00:09:05 +01:00 committed by GitHub
parent 7cc7297ea7
commit a672cd7a42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,6 +3,7 @@ import type { Ref, WatchSource } from 'vue'
import type { NuxtApp } from '../nuxt'
import { useNuxtApp } from '../nuxt'
import { createError } from './error'
import { onNuxtReady } from './ready'
export type _Transform<Input = any, Output = any> = (input: Input) => Output
@ -300,6 +301,9 @@ export async function refreshNuxtData (keys?: string | string[]): Promise<void>
if (process.server) {
return Promise.resolve()
}
await new Promise<void>(resolve => onNuxtReady(resolve))
const _keys = keys ? Array.isArray(keys) ? keys : [keys] : undefined
await useNuxtApp().hooks.callHookParallel('app:data:refresh', _keys)
}