From a672cd7a4291eb812d76b9841ec516cd8609c680 Mon Sep 17 00:00:00 2001 From: Lucie <25330882+lihbr@users.noreply.github.com> Date: Tue, 23 May 2023 00:09:05 +0100 Subject: [PATCH] fix(nuxt): await nuxt ready state before `refreshNuxtData` (#21008) --- packages/nuxt/src/app/composables/asyncData.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/nuxt/src/app/composables/asyncData.ts b/packages/nuxt/src/app/composables/asyncData.ts index a5bd1e882d..dedc712926 100644 --- a/packages/nuxt/src/app/composables/asyncData.ts +++ b/packages/nuxt/src/app/composables/asyncData.ts @@ -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: Input) => Output @@ -300,6 +301,9 @@ export async function refreshNuxtData (keys?: string | string[]): Promise if (process.server) { return Promise.resolve() } + + await new Promise(resolve => onNuxtReady(resolve)) + const _keys = keys ? Array.isArray(keys) ? keys : [keys] : undefined await useNuxtApp().hooks.callHookParallel('app:data:refresh', _keys) }