mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
fix(nuxt): don't set asyncData to existing payload on CSR if initialCache
is disabled (#6640)
This commit is contained in:
parent
006f66900e
commit
33e7fc1752
@ -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 KeysOf<T> = Array<keyof T extends string ? keyof T : string>
|
||||||
export type KeyOfRes<Transform extends _Transform> = KeysOf<ReturnType<Transform>>
|
export type KeyOfRes<Transform extends _Transform> = KeysOf<ReturnType<Transform>>
|
||||||
|
|
||||||
type MultiWatchSources = (WatchSource<unknown> | object)[];
|
type MultiWatchSources = (WatchSource<unknown> | object)[]
|
||||||
|
|
||||||
export interface AsyncDataOptions<
|
export interface AsyncDataOptions<
|
||||||
DataT,
|
DataT,
|
||||||
Transform extends _Transform<DataT, any> = _Transform<DataT, DataT>,
|
Transform extends _Transform<DataT, any> = _Transform<DataT, DataT>,
|
||||||
PickKeys extends KeyOfRes<_Transform> = KeyOfRes<Transform>
|
PickKeys extends KeyOfRes<_Transform> = KeyOfRes<Transform>
|
||||||
> {
|
> {
|
||||||
server?: boolean
|
server?: boolean
|
||||||
lazy?: boolean
|
lazy?: boolean
|
||||||
default?: () => DataT | Ref<DataT> | null
|
default?: () => DataT | Ref<DataT> | 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 = {
|
const asyncData = {
|
||||||
data: ref(nuxt.payload.data[key] ?? options.default?.() ?? null),
|
data: ref(useInitialCache() ? nuxt.payload.data[key] : options.default?.() ?? null),
|
||||||
pending: ref(!useInitialCache()),
|
pending: ref(!useInitialCache()),
|
||||||
error: ref(nuxt.payload._errors[key] ?? null)
|
error: ref(nuxt.payload._errors[key] ?? null)
|
||||||
} as AsyncData<DataT, DataE>
|
} as AsyncData<DataT, DataE>
|
||||||
|
Loading…
Reference in New Issue
Block a user