diff --git a/packages/nuxt/src/app/composables/asyncData.ts b/packages/nuxt/src/app/composables/asyncData.ts index 8fcb80a815..5f1133de8f 100644 --- a/packages/nuxt/src/app/composables/asyncData.ts +++ b/packages/nuxt/src/app/composables/asyncData.ts @@ -15,13 +15,13 @@ export type PickFrom> = T extends Array export type KeysOf = Array export type KeyOfRes = KeysOf> -type MultiWatchSources = (WatchSource | object)[]; +type MultiWatchSources = (WatchSource | object)[] export interface AsyncDataOptions< DataT, Transform extends _Transform = _Transform, PickKeys extends KeyOfRes<_Transform> = KeyOfRes - > { +> { server?: boolean lazy?: boolean default?: () => DataT | Ref | null @@ -112,10 +112,10 @@ export function useAsyncData< } } - const useInitialCache = () => options.initialCache && nuxt.payload.data[key] !== undefined + const useInitialCache = () => (nuxt.isHydrating || options.initialCache) && nuxt.payload.data[key] !== undefined const asyncData = { - data: ref(nuxt.payload.data[key] ?? options.default?.() ?? null), + data: ref(useInitialCache() ? nuxt.payload.data[key] : options.default?.() ?? null), pending: ref(!useInitialCache()), error: ref(nuxt.payload._errors[key] ?? null) } as AsyncData