Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
fix(nuxt): don't set asyncData to existing payload on CSR if `initial…
Browse files Browse the repository at this point in the history
…Cache` is disabled (#6640)
  • Loading branch information
danielroe committed Aug 15, 2022
1 parent 006f669 commit 33e7fc1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/nuxt/src/app/composables/asyncData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ export type PickFrom<T, K extends Array<string>> = T extends Array<any>
export type KeysOf<T> = Array<keyof T extends string ? keyof T : string>
export type KeyOfRes<Transform extends _Transform> = KeysOf<ReturnType<Transform>>

type MultiWatchSources = (WatchSource<unknown> | object)[];
type MultiWatchSources = (WatchSource<unknown> | object)[]

export interface AsyncDataOptions<
DataT,
Transform extends _Transform<DataT, any> = _Transform<DataT, DataT>,
PickKeys extends KeyOfRes<_Transform> = KeyOfRes<Transform>
> {
> {
server?: boolean
lazy?: boolean
default?: () => DataT | Ref<DataT> | null
Expand Down Expand Up @@ -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<DataT, DataE>
Expand Down

0 comments on commit 33e7fc1

Please sign in to comment.