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

fix(nuxt): don't set asyncData to existing payload on CSR if initialCache is disabled #6640

Merged
merged 2 commits into from
Aug 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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