fix(nuxt3): set pending to false when using cached data (#4067)

This commit is contained in:
Daniel Roe 2022-04-05 12:51:07 +01:00 committed by GitHub
parent f39fd9f0a0
commit c426f3e5e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -81,9 +81,11 @@ export function useAsyncData<
}
}
const useInitialCache = () => options.initialCache && nuxt.payload.data[key] !== undefined
const asyncData = {
data: ref(nuxt.payload.data[key] ?? options.default()),
pending: ref(true),
pending: ref(!useInitialCache()),
error: ref(nuxt.payload._errors[key] ?? null)
} as AsyncData<DataT>
@ -93,7 +95,7 @@ export function useAsyncData<
return nuxt._asyncDataPromises[key]
}
// Avoid fetching same key that is already fetched
if (opts._initial && options.initialCache && nuxt.payload.data[key] !== undefined) {
if (opts._initial && useInitialCache()) {
return nuxt.payload.data[key]
}
asyncData.pending.value = true