Share data fetched by several callers in one server render
nuxt/fetch/no-ssr-refetch-of-shared-keysrc/rule-packs/nuxt/rules/nuxt/no-ssr-refetch-of-shared-key.ts Upstream docs Run this rule
pnpm nuxt doctor --rules nuxt/fetch/no-ssr-refetch-of-shared-key
Why it matters
Callers that share a key share one asyncData entry, but during SSR Nuxt does not reuse its data. The default getCachedData returns payload data only while the browser hydrates, so on the server every later caller with the same key fetches again. The default dedupe: 'cancel' also aborts and restarts a request that is still in flight when another caller starts. A viewer composable called from route middleware, a layout, and every sidebar row made 94 identical requests in one render of vite-hub/drop. Doctor reports only when it can show that two callers run in the same render: one runs on every request (app.vue, global middleware, a universal plugin), both are in one file (such as a page's inline middleware and its setup), a page declares the other's layout or middleware, or a page or layout renders the other's component. Calls with server: false, immediate: false, enabled: false, client-only callers, and options Doctor cannot read, such as spreads or any custom getCachedData, are not reported.
Recommended fix
On the server, pass dedupe: 'defer' and getCachedData: (key, nuxtApp, ctx) => ctx.cause === 'initial' ? nuxtApp.payload.datakey : undefined. Later callers then reuse the first result and concurrent callers share one request, while refresh() and refreshNuxtData() still fetch. Keep the custom getCachedData off the client: there it would also replace Nuxt's default after hydration and stop unmounted data from being purged. In a createUseFetch((defaults) => ...) factory, write dedupe: defaults.dedupe ?? 'defer' and getCachedData: defaults.getCachedData ?? (...), because options the factory returns override the caller's.
Useful links
Example
Share the viewer request across one render
Before
// app/composables/useMe.ts
export function useMe() {
return useFetch('/api/me', { key: 'me' })
}
// app/middleware/auth.global.ts, app/layouts/default.vue, app/components/UserMenu.vue
const { data: me } = await useMe()
After
// app/composables/useMe.ts
export function useMe() {
return useFetch('/api/me', {
key: 'me',
...(import.meta.server && {
dedupe: 'defer',
getCachedData: (key, nuxtApp, ctx) =>
ctx.cause === 'initial' ? nuxtApp.payload.data[key] : undefined,
}),
})
}