@nuxt/docs 3.21.0 → 3.21.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -49,6 +49,14 @@ Working of the Nitro crawler:
49
49
 
50
50
  This is important to understand since pages that are not linked to a discoverable page can't be pre-rendered automatically.
51
51
 
52
+ ### Payload Extraction
53
+
54
+ Nuxt generates `_payload.json` alongside HTML for:
55
+ - Prerendered routes (at build time)
56
+ - ISR/SWR routes (on first request)
57
+
58
+ Payloads contain serialized data from `useAsyncData` and `useFetch`. Client-side navigation loads these cached payloads instead of re-fetching data. Configure dynamic routes like `pages/[...slug].vue` with route rules: `'/**': { isr: true }`.
59
+
52
60
  ::read-more{to="/docs/3.x/api/commands/generate#nuxt-generate"}
53
61
  Read more about the `nuxt generate` command.
54
62
  ::
@@ -13,9 +13,6 @@ surround: false
13
13
  ::card{icon="i-lucide-square-check" title="Best Practices" to="/docs/3.x/guide/best-practices"}
14
14
  Learn about best practices when developing with Nuxt.
15
15
  ::
16
- ::card{icon="i-lucide-bot" title="Working with AI" to="/docs/4.x/guide/ai"}
17
- Integrate AI tools into your Nuxt workflow with MCP Server and LLMs.txt.
18
- ::
19
16
  ::card{icon="i-lucide-box" title="Module Author Guide" to="/docs/3.x/guide/modules"}
20
17
  Learn how to create Nuxt modules to integrate, enhance or extend any Nuxt application.
21
18
  ::
@@ -193,6 +193,10 @@ The different properties you can use are the following:
193
193
  - `noScripts: boolean`{lang=ts} - Disables rendering of Nuxt scripts and JS resource hints for sections of your site.
194
194
  - `appMiddleware: string | string[] | Record<string, boolean>`{lang=ts} - Allows you to define middleware that should or should not run for page paths within the Vue app part of your application (that is, not your Nitro routes)
195
195
 
196
+ ::note
197
+ Routes using `isr` or `swr` also generate `_payload.json` files alongside HTML. Client-side navigation loads these cached payloads instead of re-fetching data. Configure dynamic routes like `pages/[...slug].vue` with glob patterns: `'/**': { isr: true }`.
198
+ ::
199
+
196
200
  Whenever possible, route rules will be automatically applied to the deployment platform's native rules for optimal performances (Netlify and Vercel are currently supported).
197
201
 
198
202
  ::important
@@ -200,6 +200,96 @@ It is highly recommended to prefix your exports to avoid conflicts with user cod
200
200
  Note that all components, pages, composables and other files that would be normally placed in your `app/` folder need to be in `runtime/app/`. This will mean they can be type checked properly.
201
201
  ::
202
202
 
203
+ ### Add Keyed Functions
204
+
205
+ Sometimes, you may need to maintain state consistency between the server and the client. Examples include Nuxt's built-in `useState` or `useAsyncData` composables. Nuxt provides a way to register such functions for automatic key injection.
206
+
207
+ When a function is registered, Nuxt’s compiler automatically injects a unique key as an additional argument if the function is called with fewer than the specified number of arguments. This key remains stable between server-side rendering and client hydration.
208
+
209
+ ::tip
210
+ The injected key is a hash derived from the file path and call location.
211
+ ::
212
+
213
+ Use the `keyedComposables` option to register your function:
214
+
215
+ ```ts
216
+ import { createResolver, defineNuxtModule } from '@nuxt/kit'
217
+
218
+ export default defineNuxtModule({
219
+ setup (options, nuxt) {
220
+ const resolver = createResolver(import.meta.url)
221
+
222
+ nuxt.options.optimization.keyedComposables.push({
223
+ name: 'useMyState',
224
+ source: resolver.resolve('./runtime/composables/state'),
225
+ argumentLength: 2,
226
+ })
227
+ },
228
+ })
229
+ ```
230
+
231
+ The `keyedComposables` configuration accepts an array of objects with the following properties:
232
+
233
+ | Property | Type | Description |
234
+ |------------------|----------|----------------------------------------------------------------------------------------------------------------------------|
235
+ | `name` | `string` | The function name. Use `'default'` for default exports (the callable name will be derived from the filename in camelCase). |
236
+ | `source` | `string` | Resolved path to the file where the function is defined. Supports Nuxt aliases (`~`, `@`, etc.) |
237
+ | `argumentLength` | `number` | Maximum number of arguments the function accepts. When called with fewer arguments, a unique key is injected. |
238
+
239
+ For example, with `argumentLength: 2`:
240
+
241
+ ```ts
242
+ useMyState() // useMyState('$HJiaryoL2y')
243
+ useMyState('myKey') // useMyState('myKey', '$HJiaryoL2y')
244
+ useMyState('a', 'b') // not transformed (already has 2 arguments)
245
+ ```
246
+
247
+ ::warning
248
+ The key injection plugin verifies the exact resolved import source of each function call. It does not follow barrel exports. The function must be exported from the exact source file specified in the `source` property.
249
+
250
+ ```ts
251
+ // ✅ Works - direct import matches the configured source
252
+ import { useMyState } from 'my-module/runtime/composables/state'
253
+
254
+ // ❌ Won't work - re-exported through a barrel file
255
+ import { useMyState } from 'my-module/runtime/composables' // index.ts barrel
256
+ ```
257
+ ::
258
+
259
+ ::warning
260
+ The function call must be statically analyzable. The compiler cannot inject keys for dynamic or indirect function calls.
261
+
262
+ ```ts
263
+ import { useMyState } from 'my-module/runtime/composables/state'
264
+ import * as composables from 'my-module/runtime/composables/state'
265
+
266
+ // ✅ Works - direct function call
267
+ useMyState()
268
+
269
+ // ✅ Works - called on namespace import
270
+ composables.useMyState()
271
+
272
+ // ❌ Won't work - dynamic property access
273
+ const name = 'useMyState'
274
+ composables[name]()
275
+
276
+ // ❌ Won't work - reassigned to a variable
277
+ const myFn = useMyState
278
+ myFn()
279
+
280
+ // ❌ Won't work - passed as a callback
281
+ someFunction(useMyState)
282
+
283
+ // ❌ Won't work - destructured with renaming in a nested scope
284
+ function setup () {
285
+ const { useMyState: localState } = composables
286
+ localState() // not transformed
287
+ }
288
+
289
+ // ...
290
+ ```
291
+ ::
292
+
203
293
  ## Add Server Routes
204
294
 
205
295
  ```ts
@@ -47,7 +47,7 @@ Let's create a `/api/login` API route that will accept a POST request with the e
47
47
  import { z } from 'zod'
48
48
 
49
49
  const bodySchema = z.object({
50
- email: z.string().email(),
50
+ email: z.email(),
51
51
  password: z.string().min(8),
52
52
  })
53
53
 
@@ -15,7 +15,7 @@ This composable is available in Nuxt v3.12+.
15
15
  ## Description
16
16
 
17
17
  A composable which observes the page title changes and updates the announcer message accordingly. Used by [`<NuxtRouteAnnouncer>`](/docs/3.x/api/components/nuxt-route-announcer) and controllable.
18
- It hooks into Unhead's [`dom:rendered`](https://unhead.unjs.io/docs/typescript/head/api/hooks/dom-rendered) to read the page's title and set it as the announcer message.
18
+ It hooks into Unhead's `dom:rendered` hook to read the page's title and set it as the announcer message.
19
19
 
20
20
  ## Parameters
21
21
 
@@ -4,7 +4,7 @@ description: "Scaffold an entity into your Nuxt application."
4
4
  links:
5
5
  - label: Source
6
6
  icon: i-simple-icons-github
7
- to: https://github.com/nuxt/cli/blob/main/packages/nuxi/src/commands/add.ts
7
+ to: https://github.com/nuxt/cli/blob/main/packages/nuxi/src/commands/add-template.ts
8
8
  size: xs
9
9
  ---
10
10
 
@@ -301,6 +301,10 @@ function addPrerenderRoutes (routes: string | string[]): void
301
301
 
302
302
  Add imports to the server. It makes your imports available in Nitro without the need to import them manually.
303
303
 
304
+ ::warning
305
+ If you want to provide a utility that works in both server and client contexts and is usable in the [`shared/`](/docs/4.x/directory-structure/shared) directory, the function must be imported from the same source file for both [`addImports`](/docs/4.x/api/kit/autoimports#addimports) and `addServerImports` and should have identical signature. That source file should not import anything context-specific (i.e., Nitro context, Nuxt app context) or else it might cause errors during type-checking.
306
+ ::
307
+
304
308
  ### Usage
305
309
 
306
310
  ```ts twoslash
@@ -24,7 +24,11 @@ Watch Vue School video about Auto-imports Nuxt Kit utilities.
24
24
 
25
25
  ## `addImports`
26
26
 
27
- Add imports to the Nuxt application. It makes your imports available in the Nuxt application without the need to import them manually.
27
+ Add imports to the Nuxt application. It makes your imports available in the Nuxt app context without the need to import them manually.
28
+
29
+ ::tip
30
+ To add imports for the Nitro server context, refer to the [`addServerImports`](/docs/4.x/api/kit/nitro#addserverimports) function.
31
+ ::
28
32
 
29
33
  ### Usage
30
34
 
@@ -61,15 +61,15 @@ We commit to support each major version of Nuxt for a minimum of six months afte
61
61
 
62
62
  The current active version of [Nuxt](https://nuxt.com) is **v4** which is available as `nuxt` on npm with the `latest` tag.
63
63
 
64
- Nuxt 3 will continue to receive maintenance updates (both bug fixes and backports of features from Nuxt 4) until the end of January 2026.
64
+ Nuxt 3 will continue to receive maintenance updates (bug fixes and security patches) until the end of July 2026.
65
65
 
66
66
  Each active version has its own nightly releases which are generated automatically. For more about enabling the Nuxt nightly release channel, see [the nightly release channel docs](/docs/3.x/guide/going-further/nightly-release-channel).
67
67
 
68
68
  | Release | | Initial release | End Of Life | Docs |
69
69
  |-----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------|----------------------------|-------------------------------------------------------------------|
70
- | **5.x** (scheduled) | | Q4 2025 (estimated) | TBA | &nbsp; |
71
- | **4.x** (stable) | <a href="https://www.npmjs.com/package/nuxt?activeTab=versions"><img alt="Nuxt latest version" src="https://img.shields.io/npm/v/nuxt.svg?logo=nuxt&label=&style=flat&colorA=18181B&colorB=28CF8D" class="not-prose h-5 w-auto" :zoom="false"></a> | 2025-07-16 | 6 months after 5.x release | [nuxt.com](/docs/3.x/getting-started/introduction) |
72
- | **3.x** (maintenance) | <a href="https://www.npmjs.com/package/nuxt?activeTab=versions"><img alt="Nuxt 3.x version" src="https://img.shields.io/npm/v/nuxt/3x.svg?logo=nuxt&label=&style=flat&colorA=18181B&colorB=28CF8D" class="not-prose h-5 w-auto" :zoom="false"></a> | 2022-11-16 | 2026-01-31 | [nuxt.com](/docs/3.x/getting-started/introduction) |
70
+ | **5.x** (scheduled) | | Q1 2026 (estimated) | TBA | &nbsp; |
71
+ | **4.x** (stable) | <a href="https://www.npmjs.com/package/nuxt?activeTab=versions"><img alt="Nuxt latest version" src="https://img.shields.io/npm/v/nuxt.svg?logo=nuxt&label=&style=flat&colorA=18181B&colorB=28CF8D" class="not-prose h-5 w-auto" :zoom="false"></a> | 2025-07-16 | 6 months after 5.x release | [nuxt.com](/docs/4.x/getting-started/introduction) |
72
+ | **3.x** (maintenance) | <a href="https://www.npmjs.com/package/nuxt?activeTab=versions"><img alt="Nuxt 3.x version" src="https://img.shields.io/npm/v/nuxt/3x.svg?logo=nuxt&label=&style=flat&colorA=18181B&colorB=28CF8D" class="not-prose h-5 w-auto" :zoom="false"></a> | 2022-11-16 | 2026-07-31 | [nuxt.com](/docs/3.x/getting-started/introduction) |
73
73
  | **2.x** (unsupported) | <a href="https://www.npmjs.com/package/nuxt?activeTab=versions"><img alt="Nuxt 2.x version" src="https://img.shields.io/npm/v/nuxt/2x.svg?logo=nuxt&label=&style=flat&colorA=18181B&colorB=28CF8D" class="not-prose h-5 w-auto" :zoom="false"></a> | 2018-09-21 | 2024-06-30 | [v2.nuxt.com](https://v2.nuxt.com/docs/get-started/installation/) |
74
74
  | **1.x** (unsupported) | <a href="https://www.npmjs.com/package/nuxt?activeTab=versions"><img alt="Nuxt 1.x version" src="https://img.shields.io/npm/v/nuxt/1x.svg?logo=nuxt&label=&style=flat&colorA=18181B&colorB=28CF8D" class="not-prose h-5 w-auto" :zoom="false"></a> | 2018-01-08 | 2019-09-21 | &nbsp; |
75
75
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/docs",
3
- "version": "3.21.0",
3
+ "version": "3.21.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/nuxt.git",