From 33e7fc175210caa94aade6813c665c965b190af0 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 15 Aug 2022 14:55:46 +0100 Subject: [PATCH] fix(nuxt): don't set asyncData to existing payload on CSR if `initialCache` is disabled (#6640) --- packages/nuxt/src/app/composables/asyncData.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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