Nuxt

nuxt/no-bare-fetch-in-setup

Load a page's initial data with useFetch or useAsyncData, not a bare $fetch at the top of script setup.

moderatestaticfe-nuxt

Why

Code at the top of <script setup> runs on the server and again in the browser during hydration. A bare $fetch there requests the same data twice, the second time while the user waits, and the browser's result can differ from the server's HTML, which gives a hydration mismatch.

Fix

Wrap the initial load: const { data, status, error } = await useFetch('/api/products'), or useAsyncData('products', () => $fetch('/api/products')) for custom logic. The server's result travels in the page payload and the browser reuses it. Keep $fetch for requests that a user action starts.

Examples

// bad (top of script setup)
const products = await $fetch('/api/products')
// good
const { data: products, status } = await useFetch('/api/products')

Sources

Facts

Id
nuxt/no-bare-fetch-in-setup
Severity
moderate
Check
static checked in the source by audit
Applies to
vue
Only in projects with
nuxt
Taught by the skill
fe-nuxt Nuxt apps
Since version
0.1.0

Rule file on GitHub

Read it in the terminal

npx github:dawidolko/frontend-skills explain nuxt/no-bare-fetch-in-setup