d48cda4081
CI / Test (ubuntu-latest, Node 18.x, bun) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, npm) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, pnpm) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, yarn) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 20.x, bun) (push) Failing after 17m13s
CI / Test (ubuntu-latest, Node 20.x, npm) (push) Failing after 18m42s
CI / Test (ubuntu-latest, Node 20.x, pnpm) (push) Failing after 15m0s
CI / Test (ubuntu-latest, Node 20.x, yarn) (push) Failing after 49m44s
CI / Test (ubuntu-latest, Node 22.x, bun) (push) Failing after 51m55s
CI / Test (ubuntu-latest, Node 22.x, pnpm) (push) Failing after 21m57s
CI / Test (ubuntu-latest, Node 22.x, npm) (push) Failing after 37m39s
CI / Test (ubuntu-latest, Node 22.x, yarn) (push) Failing after 34m7s
CI / Validate Components (push) Failing after 37m15s
CI / Python Tests (push) Failing after 10m1s
CI / Security Scan (push) Failing after 10m1s
CI / Lint (push) Failing after 17m12s
CI / Coverage (push) Failing after 20m19s
CI / Test (macos-latest, Node 18.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, yarn) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, yarn) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, yarn) (push) Has been cancelled
2.6 KiB
2.6 KiB
paths
| paths | ||||||
|---|---|---|---|---|---|---|
|
Nuxt Patterns
This file extends common/patterns.md with Nuxt specific content.
Data-fetch selection
Load-bearing. Pick by render timing, not habit.
useFetch(url)= SSR-safe, URL-first initial/first-paint data. The default. Forwards the server result through the payload so there is no hydration double-fetch.useAsyncData(key, fn)= SSR-safe, custom async logic (SDK / GraphQL / combined calls). The explicit key shares the result across components.$fetch= client interactions only (form submit, button click, POST/PUT/DELETE). NOT SSR-safe, double-fetches if used for first paint.- Rule:
useFetch/useAsyncDatafor anything rendered on first paint,$fetchonly for event-driven mutations.
Shared state
useState('key', () => init)for SSR-safe shared state. Values must be JSON-serializable.- NEVER
export const x = ref()at module scope. One shared instance leaks across concurrent SSR requests and causes a memory leak. - With
@pinia/nuxt: Pinia for domain state,useStatefor small cross-component primitives. - Async server-side init goes in
callOnce(async () => {...}), not as a side effect insideuseAsyncData.
Nitro server routes
server/api/*.{get,post}.tsauto-register by path + method. Handler isdefineEventHandler((event) => ...).- Errors via
throw createError({ status, statusText }). Prefer the Web-APIstatus/statusTextover deprecatedstatusCode/statusMessage. server/middleware/must NOT return a response. Only mutateevent.contextor set headers.
Route middleware
app/middleware/*.tswithdefineNuxtRouteMiddleware((to, from) => ...).- Use the
to/fromargs. Do NOT calluseRoute()inside middleware. .globalsuffix runs on every route. ReturnnavigateTo()to redirect,abortNavigation()to stop.
Hydration-safe rendering
- Route off
status(idle | pending | success | error) for lazy fetches. useAsyncDatapayload usesdevalue(Date/Map/Set/refs survive). Aserver/apiresponse isJSON.stringify-only, so definetoJSON()for non-JSON types.- Shrink payload with
pick/transform. This reduces serialized size, it does not skip the fetch.
Reference
- ECC skills:
nuxt4-patterns,vite-patterns,frontend-patterns. - Nuxt data fetching
- Nuxt state management
- Nuxt server engine (Nitro)