fix(nuxt): warn when async data doesn't return a value (#27599)

This commit is contained in:
Daniel Roe 2024-06-14 23:11:25 +01:00 committed by GitHub
parent d6e723885d
commit 6a19aa79f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -311,6 +311,11 @@ export function useAsyncData<
result = pick(result as any, options.pick) as DataT result = pick(result as any, options.pick) as DataT
} }
if (import.meta.dev && import.meta.server && !result) {
// @ts-expect-error private property
console.warn(`[nuxt] \`${options._functionName || 'useAsyncData'}\` should return a value that is not \`null\` or \`undefined\` or the request may be duplicated on the client side.`)
}
nuxtApp.payload.data[key] = result nuxtApp.payload.data[key] = result
asyncData.data.value = result asyncData.data.value = result