fix(nuxt): sync useNuxtData and useAsyncData

This commit is contained in:
94726 2023-07-21 23:36:52 +02:00
parent 429d3656e9
commit 6664dcccb9

View File

@ -120,8 +120,9 @@ export function useAsyncData<
// Setup nuxt instance payload // Setup nuxt instance payload
const nuxt = useNuxtApp() const nuxt = useNuxtApp()
const getCachedData = () => nuxt.isHydrating ? nuxt.payload.data[key] : nuxt.static.data[key] // toRef to make sure asyncData and useNuxtData are synced
const hasCachedData = () => getCachedData() !== undefined const getCachedData = () => nuxt.isHydrating ? toRef(nuxt.payload.data, key) : nuxt.static.data[key]
const hasCachedData = () => unref(getCachedData()) !== undefined
// Create or use a shared asyncData entity // Create or use a shared asyncData entity
if (!nuxt._asyncData[key]) { if (!nuxt._asyncData[key]) {