Under The Hood
frontend vue Nuxt 3.x / Vue 3.x

Nuxt 3 useAsyncData: Payload Hydration & SSR Request Deduplication

Last updated
Prerequisites:
Nuxt 3 SSR fundamentals
Vue 3 Composition API
  • vue
  • nuxt
  • useAsyncData
  • useFetch
  • ssr
  • hydration
  • deduplication

Read at your depth

The practical view

`useAsyncData(key, handler)` is Nuxt 3's composable for fetching data during Server-Side Rendering (SSR) without duplicating the network request on client hydration. `const { data, pending, error, refresh } = await useAsyncData('users', () => $fetch('/api/users'))`. Nuxt executes the handler on the server, inlines the result into the SSR payload (`nuxtApp.payload.data[key]`), and on client hydration, reads directly from the payload cache.

The same idea in other frameworks

react equivalent
Next.js React Server Components passing serialized props to client boundaries.

Legacy vs modern

Naive onMounted Client Fetch vs Nuxt useAsyncData SSR Hydration

Fetching in `onMounted` causes layout shifts and double-fetching; `useAsyncData` renders on the server and hydrates from payload.

before → after
Client-Only Fetch (Double Fetch / Layout Shift)
onMounted(async () => { users.value = await $fetch('/api/users'); }); // ❌ Fails SSR & SEO
Nuxt 3 useAsyncData SSR Payload
const { data: users } = await useAsyncData('users', () => $fetch('/api/users')); // ✅ NEW

Interview gotchas

Context

Interviewers test your knowledge of Nuxt's auto-generated key heuristics.

The mechanical answer

If the `key` argument is omitted (e.g. `useAsyncData(() => $fetch(...))`), Nuxt auto-generates a key based on the file path and line number of the call site. However, if you extract `useAsyncData` into a shared custom composable called from multiple components, they will share the *same* auto-generated key, causing one call to overwrite the other's payload. Always provide an explicit unique key when wrapping in custom composables.

Trap

Never use dynamic runtime IDs (e.g. `Math.random()`) as the key; keys must be deterministic between server and client for payload hydration matching.

Under The Hood — a multi-depth technical interview hub.

Third-party licenses Press ⌘ K to search.