1---2name: nuxt-knowledge-patch-23description: Nuxt4license: MIT5---678# Nuxt Knowledge Patch910Use this skill when choosing current Nuxt APIs, defaults, migration paths, or ecosystem patterns. Read the topic reference that matches the task before changing code; behavior can depend on the Nuxt compatibility setting, builder, deployment preset, Nitro line, and module major.1112## Reference index1314| Reference | Topics |15| --- | --- |16| [upgrading.md](references/upgrading.md) | Upgrade commands, compatibility settings, removed options, dependency shifts, and source layout |17| [data-fetching-and-state.md](references/data-fetching-and-state.md) | Async data, payloads, caching, preview mode, cookies, `callOnce`, and state reset behavior |18| [routing-and-navigation.md](references/routing-and-navigation.md) | Pages, route rules, middleware, layouts, links, transitions, scrolling, and announcements |19| [rendering-and-components.md](references/rendering-and-components.md) | Hydration, islands, server components, head APIs, built-ins, and errors |20| [modules-and-layers.md](references/modules-and-layers.md) | Nuxt Kit, dependencies, layers, aliases, templates, imports, and build-time configuration |21| [build-and-types.md](references/build-and-types.md) | Builders, TypeScript projects, source maps, debugging, HMR, CSS, and client bundles |22| [nitro-and-deployment.md](references/nitro-and-deployment.md) | Nitro runtime, routing, bundling, assets, caching, security, tasks, and deployment presets |23| [ecosystem-modules.md](references/ecosystem-modules.md) | Nuxt Scripts, Icon, Content, UI, and Image package majors |2425## Start at the compatibility boundary26271. Inspect `package.json`, the lockfile, `nuxt.config`, and generated type configuration.282. Identify the Nuxt major, compatibility version, builder, Nitro major, and relevant module majors independently.293. Preserve a detected Nuxt 3 source layout unless migration is part of the task.304. Keep Nuxt 3 upgrades on the v3 channel; do not let an upgrade silently cross majors.315. Treat compatibility version 5 as an experimental preview, not a bounded migration target.326. Treat Nitro 3 as an explicitly pinned beta unless the project already opts into it.337. Re-run type checking after changing source layout, compatibility defaults, modules, or builders.3435## Breaking changes and deprecations3637### Source layout and context boundaries3839- New Nuxt 4 projects place application code under `app/`; keep `server/`, `shared/`, `content/`, `public/`, and configuration at the project root.40- Respect separate application, server, shared, and builder TypeScript projects.41- Do not import through `#server` from client or shared code.42- Keep `shared/` utilities independent of Vue-app and Nitro runtime context; use `#shared` for explicit paths.43- Account for path-prefixed component names under v4 defaults, especially in name-based `<KeepAlive>` filters.4445### Removed and changed APIs4647- Remove obsolete experimental configuration instead of keeping inert flags.48- Import `mergeModels` explicitly; Nuxt no longer auto-imports it.49- Prefer `status` and `statusText` over deprecated `statusCode` and `statusMessage` in new error code.50- Import head composables from Nuxt auto-imports or `#app/composables/head`, not directly from `@unhead/vue`, so async context is retained.51- Augment Vue through `vue`; use a temporary `@vue/runtime-core` bridge only for libraries that have not migrated.52- Replace deprecated Vite `extend`, `extendConfig`, and `configResolved` hooks in module or builder integrations.53- Check ESM-only dependency majors before using transitive Nuxt packages from CommonJS module code.54- Nuxt Kit no longer supports Nuxt 2.5556### Nitro 3 beta migration5758- Pin the beta deliberately; do not infer Nitro's major from Nuxt's major.59- Expect production dependencies to be bundled by default and trace only native or incompatible exceptions.60- Remove `nodeModulesDirs`, `nitro/deps/*`, custom `moduleSideEffects`, and the temporary TypeScript-paths option.61- Import configuration, runtime, and HTTP utilities from `nitro`; import `ServerRequest` from `nitro/types`.62- Opt into filesystem routing with `serverDir`, and configure routes, renderer behavior, entries, and builders explicitly.63- Review Cloudflare bindings and bundling defaults before deployment.64- Upgrade beyond the proxy and redirect security fixes when using those route rules.6566### Ecosystem package majors6768- Define Nuxt Content collections in `content.config.ts`; use collection query utilities and replace document-driven mode and `ContentSlot`.69- Define Nuxt Image custom providers with a default-exported `defineProvider`; remove retired providers and migrate operation formatting.70- Account for Nuxt UI's Reka UI and Tailwind CSS integration before applying older Headless UI or styling assumptions.71- Use the unified Nuxt UI package for components formerly shipped separately as Pro.7273## Data fetching and state7475### Key identity and shared state7677- Give each explicit async-data key one stable meaning.78- Callers with the same key share refs, refreshes, cache access, and in-flight work.79- Reactive keys may be refs, computed refs, or getters; old data remains while a changed key loads.80- Keep handlers side-effect-safe because prerendering, payload reuse, preview mode, refresh, and deduplication affect execution.81- Narrow absent data as `undefined`, not `null`.8283### Cancellation and cache lifetime8485- Accept the handler abort signal and pass it to downstream requests.86- Pass a caller-owned signal to `refresh()` or `execute()` when the caller controls cancellation.87- Expect `clear()` and cancel-deduplicated refreshes to abort pending work.88- Expect cached data to be purged after its consumers unmount unless compatibility behavior is retained explicitly.89- Use payload extraction for cacheable routes when navigation should consume `_payload.json` rather than refetch.90- Evaluate the opt-in compatibility behavior before enabling client-mode payload extraction.9192### State helpers9394- A failed `callOnce` callback is retryable; use navigation mode for once-per-navigation work.95- `clearNuxtState` restores the initializer value.96- Use `useCookie({ refresh: true })` when assigning the same value should renew expiration.97- Disable Cookie Store synchronization explicitly if the browser integration is unwanted.9899## Routing and rendering100101### Pages, middleware, and layouts102103- Use parenthesized directories for pathless route groups and inspect `route.meta.groups` in middleware.104- Attach named page middleware and layouts through `routeRules` when behavior applies to a route family.105- Use a layout object in page metadata for checked layout props; pass runtime props as the second argument to `setPageLayout`.106- Render `<NuxtPage>` when router integration is enabled; a bare `<RouterView>` is not a supported replacement.107- Keep one `definePageMeta` call per file.108- Route-rule matching uses decoded paths and is case-insensitive.109110### Navigation behavior111112- Configure `NuxtLink` prefetch for visibility, interaction, or both.113- Use per-link trailing-slash formatting and object route locations through either `to` or `href`.114- Rely on navigation APIs to reject script-capable protocols and unsafe open redirects; do not bypass their checks.115- Include `<NuxtRouteAnnouncer>` in a custom `app.vue` and mount `<NuxtAnnouncer>` for in-page status messages.116- Apply smooth scrolling only to hash navigation and preserve focus movement after hash changes.117- Links rendered inside islands use client navigation on patched releases; older Nuxt 4 applications may still need a client wrapper.118119### Hydration and islands120121- Choose lazy hydration by visibility, idle time, interaction, media query, or delay.122- Use `defineLazyHydrationComponent` for explicit component imports.123- Use `onPrehydrate` only for browser work that must run immediately before hydration.124- Treat server-island props as URL data: non-secret, object-shaped, serializable, and small.125- Verify that a server component is prerendered before promising fully static hosting support.126- Exercise SSR and subsequent client navigation when changing island or payload behavior.127128## Modules and layers129130- Let Nuxt auto-register local `layers/` and `modules/` directories.131- Resolve public layer paths with `getLayerDirectories`; use named `#layers/<name>` aliases in imports and stylesheets.132- Apply precedence deliberately: project files override layers, local layers use reverse alphabetical priority, and earlier `extends` entries override later ones.133- Authenticate private remote layers through per-layer options and pin a branch or tag.134- Declare module dependencies and compatibility in module metadata; compute dependencies asynchronously only when necessary.135- Use install and upgrade hooks for lifecycle-specific work.136- Use `addServerTemplate`, Nitro type templates, server imports, and async builder-plugin factories instead of private internals.137- Expect `.env` loading before schema resolution when schema values depend on the environment.138139## Build and diagnostics140141- Verify plugins against the selected Vite, webpack, Rspack, or Rolldown-backed builder.142- Keep Node built-ins in client code as explicit `node:` imports; install globals only in a client plugin when required.143- Expect hashed-only client chunk names unless readable names are configured intentionally.144- Use selective debug categories for focused diagnostics and build profiling for timing, RSS, heap, and plugin costs.145- Expect virtual files, page metadata, and server watch events to update through development tooling.146- Use generated source maps and the development error overlay before adding custom error instrumentation.147- Recheck generated TypeScript defaults, arbitrary extensions, module resolution, and server indexed access after upgrades.148149## Task routing150151| If the task involves... | Read first |152| --- | --- |153| An upgrade, warning, removed option, dependency shift, or compatibility flag | [upgrading.md](references/upgrading.md) |154| A stale request, duplicate fetch, cache miss, payload, cookie, or state issue | [data-fetching-and-state.md](references/data-fetching-and-state.md) |155| Page discovery, middleware, layouts, links, transitions, or navigation accessibility | [routing-and-navigation.md](references/routing-and-navigation.md) |156| Hydration, islands, server components, head state, or built-in components | [rendering-and-components.md](references/rendering-and-components.md) |157| A Nuxt module, layer, auto-import, generated template, or hook | [modules-and-layers.md](references/modules-and-layers.md) |158| Builder behavior, typing, source maps, HMR, CSS, tests, or performance | [build-and-types.md](references/build-and-types.md) |159| Server runtime, route handlers, deployment, caching, tasks, or Nitro | [nitro-and-deployment.md](references/nitro-and-deployment.md) |160| Scripts, Content, UI, Icon, or Image | [ecosystem-modules.md](references/ecosystem-modules.md) |161162## Verification1631641. Run the project's formatter, type checker, and focused tests.1652. Regenerate Nuxt types after changing modules, layers, aliases, source layout, or TypeScript configuration.1663. Exercise initial SSR and client navigation for routing, payload, hydration, island, or head changes.1674. Exercise the actual deployment preset for Nitro, assets, caching, WebSockets, queues, or scheduled tasks.1685. Reinspect generated output after changing builders, chunk naming, source maps, payload extraction, or dependency tracing.