Nuxt · Data fetching

NUXT0040Keep useFetch lifecycle callbacks replay-safe

Flags mutation toast in useFetch callback in Nuxt project code before it leaks into runtime behavior.

Why it happens

Nuxt data fetching relies on stable keys, payload serialization, and request context. Bypassing those contracts can duplicate requests or lose SSR data.

Fix

Remove mutation toast in useFetch callback, or move it to the Nuxt runtime/API that owns that behavior.

Example

Move callback effects into actions

Before

await useFetch('/api/orders', {
  method: 'POST',
  onResponse() {
    toast.add({ title: 'Saved' })
  },
})

After

async function saveOrder() {
  await $fetch('/api/orders', { method: 'POST' })
  toast.add({ title: 'Saved' })
}

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/no-mutation-toast-in-usefetch-callback
Copyright © 2026