Return a value from useAsyncData handlers
nuxt/fetch/handler-must-returnsrc/rule-packs/nuxt/rules/nuxt/async-data-handler-must-return.ts Upstream docs Run this rule
pnpm nuxt doctor --rules nuxt/fetch/handler-must-return
Why it matters
A handler that resolves to undefined leaves no data in the payload. During hydration, Nuxt skips the fetch if the payload contains data or an error; otherwise the handler can run again and Nuxt warns in development (NUXT_E3006). Arrow functions with an expression body count as returning, and handlers that always throw are not reported. Doctor skips client-only calls, apps with ssr: false, calls with server: false, immediate: false, enabled: false, a transform, pick, default, or getCachedData option, and options it cannot read. Side effects inside the handler are reported separately by nuxt/async-data-handler-pure (NUXT0017).
Recommended fix
Return the data the page renders. If the handler only runs side effects, return null, or move the side effects out of useAsyncData.
Useful links
Example
Return the fetched data
Before
const store = useCartStore()
await useAsyncData('cart', async () => {
store.items = await $fetch('/api/cart')
})
After
const { data: items } = await useAsyncData('cart', () => $fetch('/api/cart'))