1---2name: nuxt-knowledge-patch3description: Nuxt4license: MIT5---678# Nuxt Knowledge Patch910Use this skill when choosing current Nuxt APIs, defaults, migration paths, or11ecosystem patterns. Read the topic reference that matches the task before12changing code: behavior can differ by compatibility mode, builder, deployment13preset, Nitro channel, or module major.1415## Reference index1617| Reference | Topics |18| --- | --- |19| [upgrading.md](references/upgrading.md) | Major migrations, release channels, compatibility settings, removed options, dependency changes, and upgrade commands |20| [data-fetching-and-state.md](references/data-fetching-and-state.md) | `useAsyncData`, `useFetch`, payloads, caching, preview mode, cookies, `callOnce`, and state reset behavior |21| [routing-and-navigation.md](references/routing-and-navigation.md) | Pages, route rules, middleware, layouts, links, transitions, scrolling, and announcements |22| [rendering-and-components.md](references/rendering-and-components.md) | Hydration, server components, islands, head APIs, built-ins, errors, and runtime hooks |23| [modules-and-layers.md](references/modules-and-layers.md) | Nuxt Kit, module dependencies, layers, aliases, templates, imports, and build-time configuration |24| [build-and-types.md](references/build-and-types.md) | Builders, TypeScript projects, source maps, debugging, profiling, HMR, CSS, and client bundles |25| [nitro-and-deployment.md](references/nitro-and-deployment.md) | Nitro runtime, beta migration, routing, assets, caching, security, tasks, and deployment presets |26| [ecosystem-modules.md](references/ecosystem-modules.md) | Nuxt Scripts, Icon, Content, UI, and Image package majors |2728## Start with the compatibility boundary29301. Inspect `package.json`, the lockfile, `nuxt.config`, and generated type31 configuration.322. Identify the Nuxt major, compatibility version, builder, Nitro major, and33 relevant ecosystem-module majors independently.343. Keep Nuxt 3 applications on the v3 release channel when upgrading, using35 the deduplicating upgrade command.364. Treat compatibility version 5 as an experimental preview, not a bounded37 migration target.385. Treat Nitro 3 as an explicitly pinned beta unless the project already opts39 into it; do not infer Nitro's major from Nuxt's major.406. Re-run type checking after changing source layout, compatibility defaults,41 modules, builders, or generated aliases.4243## Breaking changes and deprecations4445### Source layout and context boundaries4647- Expect application code under `app/` in new Nuxt 4 projects; keep `server/`,48 `shared/`, `content/`, `public/`, and configuration at the project root.49- Preserve a detected Nuxt 3 layout unless the task explicitly includes a50 migration.51- Respect separate application, server, shared, and builder TypeScript52 projects. Do not import `#server` from client or shared code.53- Keep `shared/` context-independent and use `#shared` for explicit imports.54- Account for path-prefixed component names under v4 defaults, especially in55 name-based `<KeepAlive>` filters.5657### Removed and changed APIs5859- Remove obsolete experimental configuration rather than retaining inert60 flags.61- Import `mergeModels` explicitly; it is no longer auto-imported.62- Prefer `status` and `statusText` over deprecated `statusCode` and63 `statusMessage` in new error code.64- Import head composables from Nuxt auto-imports or65 `#app/composables/head`, not directly from `@unhead/vue`, to preserve async66 context.67- Augment Vue through `vue`; bridge legacy `@vue/runtime-core` augmentation68 only as a temporary compatibility measure.69- Replace deprecated Vite extension hooks in module and builder integrations.70- Check ESM-only dependency majors before relying on transitive Nuxt packages71 from CommonJS module code.7273### Nitro beta migration7475- Pin the intended beta explicitly before adopting Nitro 3 behavior.76- Expect production dependencies to be bundled by default; trace only native77 or incompatible exceptions.78- Remove `nodeModulesDirs`, `nitro/deps/*`, custom `moduleSideEffects`, and the79 temporary TypeScript-paths option.80- Import configuration, runtime, and HTTP utilities from the root `nitro`81 package; import `ServerRequest` from `nitro/types`.82- Opt into filesystem routing with `serverDir`, and configure routes, renderer83 behavior, entries, and builders explicitly where needed.84- Review Cloudflare binding access and bundling defaults before deployment.85- Upgrade past the proxy and redirect security fixes when those route rules86 are in use.8788### Ecosystem package majors8990- Define Content collections in `content.config.ts`; migrate queries to91 collection utilities and replace removed document-driven and `ContentSlot`92 APIs.93- Define Image custom providers with a default-exported `defineProvider`;94 remove retired providers and update operation formatting.95- Account for UI's Reka UI and Tailwind CSS integration before applying old96 Headless UI or styling assumptions.97- Use the unified UI package for components that were previously separate Pro98 offerings.99100## Data fetching and state101102### Key identity and shared state103104- Give each explicit async-data key one stable meaning.105- Expect callers with the same key to share refs, refreshes, cached-data106 lookup, and in-flight work.107- Use reactive keys when data identity follows a ref, computed ref, or getter;108 expect old data to remain while a changed key loads.109- Keep handlers side-effect-safe because prerendering, payload reuse, preview110 mode, refresh, and deduplication can change when they run.111- Narrow absent data as `undefined`, not `null`.112113### Cancellation and cache lifetime114115- Accept the handler abort signal and pass it to downstream requests.116- Pass a caller-owned signal to `refresh()` or `execute()` when the caller117 controls cancellation.118- Expect `clear()` and cancel-deduplicated refreshes to abort pending work.119- Expect cached data to be purged after its consumers unmount unless legacy120 compatibility is explicitly retained.121- Use payload extraction for cacheable routes when client navigation should122 consume `_payload.json` instead of refetching.123- Enable client-mode payload extraction only after evaluating its opt-in124 compatibility behavior.125126### State helpers127128- Expect a failed `callOnce` callback to be retryable; use navigation mode for129 once-per-navigation work.130- Expect `clearNuxtState` to restore the initializer value.131- Set `useCookie({ refresh: true })` when assigning the same value should renew132 expiration.133- Disable Cookie Store synchronization explicitly when the browser integration134 is unwanted.135136## Routing and rendering137138### Pages, middleware, and layouts139140- Use parenthesized directories for pathless route groups and inspect141 `route.meta.groups` in middleware.142- Attach named page middleware and layouts through `routeRules` when behavior143 applies to a route family.144- Use a layout object in page metadata for type-checked props; pass runtime145 props as the second argument to `setPageLayout`.146- Render `<NuxtPage>` when router integration is enabled; a bare147 `<RouterView>` is not a supported replacement.148- Keep one `definePageMeta` call per file.149150### Navigation behavior151152- Configure `NuxtLink` prefetch triggers for visibility, interaction, or both.153- Use per-link trailing-slash formatting and object route locations through154 either `to` or `href` as appropriate.155- Rely on navigation APIs to reject script-capable protocols and unsafe open156 redirects; do not bypass their checks.157- Include `<NuxtRouteAnnouncer>` in a custom `app.vue` and mount158 `<NuxtAnnouncer>` for non-navigation status messages.159- Apply smooth-scroll configuration to hash scrolling and preserve focus160 behavior after hash navigation.161162### Hydration and islands163164- Choose lazy hydration by visibility, idle time, interaction, media query, or165 delay; use `defineLazyHydrationComponent` for explicit imports.166- Use `onPrehydrate` only for browser work immediately before hydration.167- Treat server-island props as URL data: keep them non-secret, serializable,168 object-shaped, and small.169- Verify whether a server component is present during prerender or first170 appears after client navigation before promising static-host support.171- Current island links navigate client-side; do not retain an obsolete wrapper172 whose only job was preventing full-page navigation.173174## Modules, layers, and builds175176### Modules and layers177178- Let Nuxt auto-register local `layers/` and `modules/` directories.179- Resolve layer paths with `getLayerDirectories`; use named180 `#layers/<name>` aliases in imports and stylesheets.181- Apply precedence deliberately: project files override layers, local layers182 use reverse alphabetical priority, and earlier `extends` entries override183 later ones.184- Authenticate private remote layers through per-layer options and pin their185 branch or tag.186- Declare module dependencies and compatibility in metadata; use async187 dependency calculation only when necessary.188- Use install and upgrade hooks for lifecycle-specific module work.189- Use `addServerTemplate`, Nitro type templates, server imports, and async190 builder-plugin factories instead of private internals.191- Expect `.env` loading before schema resolution.192193### Build and diagnostics194195- Verify plugins against the selected Vite, webpack, Rspack, or196 Rolldown-backed builder rather than assuming Vite-only behavior.197- Keep Node built-ins in client code as explicit `node:` imports; install198 globals only in a client plugin when a dependency truly requires them.199- Expect hashed-only client chunk names unless readable names are configured200 intentionally.201- Use selective debug categories for focused diagnostics and build profiling202 for timing, RSS, heap, and plugin costs.203- Expect virtual files, page metadata, and server-file watch events to update204 through HMR.205- Use generated source maps and the development error overlay before adding206 custom error instrumentation.207- Recheck generated TypeScript defaults, module resolution, arbitrary208 extensions, and server indexed access after upgrades.209210## Task routing211212| If the task involves... | Read first |213| --- | --- |214| An upgrade, warning, removed option, or compatibility flag | [upgrading.md](references/upgrading.md) |215| A stale request, duplicate fetch, cache miss, or payload issue | [data-fetching-and-state.md](references/data-fetching-and-state.md) |216| Page discovery, middleware, layouts, links, or navigation accessibility | [routing-and-navigation.md](references/routing-and-navigation.md) |217| Hydration, islands, server components, head state, or built-ins | [rendering-and-components.md](references/rendering-and-components.md) |218| A module, layer, auto-import, generated template, or hook | [modules-and-layers.md](references/modules-and-layers.md) |219| Builder behavior, typing, source maps, HMR, CSS, or performance | [build-and-types.md](references/build-and-types.md) |220| Server runtime, route handlers, deployment, caching, tasks, or Nitro | [nitro-and-deployment.md](references/nitro-and-deployment.md) |221| Scripts, Content, UI, Icon, or Image | [ecosystem-modules.md](references/ecosystem-modules.md) |222223## Verification2242251. Run the project's formatter, type checker, and focused tests.2262. Regenerate Nuxt types after changing modules, layers, aliases, source227 layout, or TypeScript configuration.2283. Exercise initial SSR and client navigation for routing, payload, hydration,229 island, or head changes.2304. Exercise the actual deployment preset for Nitro, asset, cache, WebSocket,231 queue, or scheduled-task changes.2325. Reinspect generated output when changing builders, chunk naming, source233 maps, payload extraction, or dependency tracing.