Nuxt · SSR safety

NUXT0105Keep request data out of module-scope state

Report module-scope ref(), reactive(), and plain objects or arrays that server-rendered app code writes request data into.

Why it happens

On the server, Nuxt imports the app bundle once and creates a new Vue app and Nuxt app for every request, but module-scope values are not recreated. A ref, reactive object, or plain object declared at module scope, or in the plain <script> block of a component, is shared by every request. When setup, a composable, a plugin, or route middleware writes the route, request headers, cookies, or the request event into it during server rendering, concurrent requests overwrite each other and one user's data can render for another. Doctor skips state created inside setup or the composable, useState, writes in onMounted, behind import.meta.client, or in event handlers, client-only files, apps that turn SSR off, and helpers it cannot trace to Vue or Nuxt. Map, Set, and reassigned module variables are reported by nuxt/ssr/no-module-scope-request-state.

Fix

Create state per request in local variables or with setup-local ref() or reactive(). Keep credentials and request objects in server-only request context. Nuxt writes useState() to nuxtApp.payload.state, so use it only for serializable values intended for the browser and safe to send in the hydration payload.

Example

Create request state with useState

Before

const activeFilter = ref<string>()

export function useFilters() {
  activeFilter.value = useRoute().query.filter as string
  return activeFilter
}

After

export function useFilters() {
  const activeFilter = useState<string | undefined>('active-filter')
  activeFilter.value = useRoute().query.filter as string
  return activeFilter
}

Verify the fix

Run only this rule after editing so the report stays focused on the diagnostic you are closing:

pnpm nuxt doctor --rules nuxt/ssr/no-request-data-in-module-state
Copyright © 2026