Nuxt · NUXT0106

Keep per-request state out of pages served from a shared cache

Report a page that reads request headers, cookies, or the request event while it renders on the server, when Nitro's route rules serve that page from a shared cache (cache, swr, isr, or prerender).
NUXT0106vite-doctor/nuxtssrwarnSuggestion

Run this rule

pnpm nuxt doctor --rules nuxt/ssr/no-request-state-in-cached-page

Why it matters

Nitro merges matching route rules most specific first. A cached handler receives only the request headers listed in cache.varies but retains the original event.context. Doctor checks the resolved rules in a current Nuxt manifest, including inline defineRouteRules and nitro.routeRules. It skips client-only reads and routes that bypass SSR through a redirect, proxy, or ssr: false. For cache and swr, a read is covered only when all its known headers are listed in cache.varies; varying on headers does not prove coverage for event.context. URL queries are part of Nitro's runtime cache key, but static prerendered files do not vary by query. Doctor reports ISR only for verified production preset and route combinations, and records evidence gaps for unproven cache coverage, such as dynamic page routes or stale page inputs.

Move the per-visitor part to the client (onMounted(), import.meta.client, or <ClientOnly>) or to an uncached API call, or exclude the route from the cache with cache: false, isr: false, or prerender: false. For a cache keyed on a header, list it in cache.varies.

Example

Read the session on the client of a cached page

Before

<!-- routeRules: { '/pricing': { swr: 3600 } } -->
<script setup lang="ts">
const headers = useRequestHeaders(['cookie'])
const { data: plan } = await useFetch('/api/me/plan', { headers })
</script>

After

<!-- routeRules: { '/pricing': { swr: 3600 } } -->
<script setup lang="ts">
const { data: plan } = useFetch('/api/me/plan', { server: false })
</script>
Copyright © 2026