@nuxt/docs-nightly 4.4.0-29506647.0fa65fc3 → 4.4.0-29532435.dd5ca638

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.
@@ -20,13 +20,14 @@ Or follow the steps below to set up a new Nuxt project on your computer.
20
20
  ### Prerequisites
21
21
 
22
22
  - **Node.js** - [`20.x`](https://nodejs.org/en) or newer (but we recommend the [active LTS release](https://github.com/nodejs/release#release-schedule))
23
- - **Text editor** - There is no IDE requirement, but we recommend [Visual Studio Code](https://code.visualstudio.com/) with the [official Vue extension](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (previously known as Volar) or [WebStorm](https://www.jetbrains.com/webstorm/), which, along with [other JetBrains IDEs](https://www.jetbrains.com/ides/), offers great Nuxt support right out-of-the-box.
23
+ - **Text editor** - There is no IDE requirement, but we recommend [Visual Studio Code](https://code.visualstudio.com/) with the [official Vue extension](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (previously known as Volar) or [WebStorm](https://www.jetbrains.com/webstorm/), which, along with [other JetBrains IDEs](https://www.jetbrains.com/ides/), offers great Nuxt support right out-of-the-box. If you use another editor, such as Neovim, you can configure [Vue Language Server](https://github.com/vuejs/language-tools) support by following the [Vue Language Tools setup guides](https://github.com/vuejs/language-tools/wiki).
24
24
  - **Terminal** - In order to run Nuxt commands
25
25
 
26
26
  ::note
27
27
  ::details
28
28
  :summary[Additional notes for an optimal setup:]
29
29
  - **Node.js**: Make sure to use an even numbered version (20, 22, etc.)
30
+ - **Neovim**: When configuring the Vue TypeScript plugin, make sure `location` points to the `@vue/language-server` package directory, not its binary. See the [Neovim setup guide](https://github.com/vuejs/language-tools/wiki/Neovim) for a working configuration.
30
31
  - **WSL**: If you are using Windows and experience slow HMR, you may want to try using [WSL (Windows Subsystem for Linux)](https://learn.microsoft.com/en-us/windows/wsl/install) which may solve some performance issues.
31
32
  - **Windows slow DNS resolution**: Instead of using `localhost:3000` for local dev server on Windows, use `127.0.0.1` for much faster loading experience on browsers.
32
33
  ::
@@ -120,9 +120,8 @@ In most cases, Nuxt can work with third-party content that is not generated or c
120
120
 
121
121
  Accordingly, you should make sure that the following options are unchecked / disabled in Cloudflare. Otherwise, unnecessary re-rendering or hydration errors could impact your production application.
122
122
 
123
- 1. Speed > Optimization > Content Optimization > Disable "Rocket Loader™"
124
- 2. Speed > Optimization > Image Optimization > Disable "Mirage"
125
- 3. Scrape Shield > Disable "Email Address Obfuscation"
123
+ 1. Speed > Settings > Content Optimization > Disable "Rocket Loader™"
124
+ 2. Security > Settings > Disable "Email Address Obfuscation"
126
125
 
127
126
  With these settings, you can be sure that Cloudflare won't inject scripts into your Nuxt application that may cause unwanted side effects.
128
127
 
@@ -142,9 +142,8 @@ Images in your website can usually be separated by importance; the ones that are
142
142
  <NuxtImg
143
143
  src="/hero-banner.jpg"
144
144
  format="webp"
145
- preload
145
+ :preload="{ fetchPriority: 'high' }"
146
146
  loading="eager"
147
- fetch-priority="high"
148
147
  width="200"
149
148
  height="100"
150
149
  />
@@ -154,7 +153,7 @@ Images in your website can usually be separated by importance; the ones that are
154
153
  src="/facebook-logo.jpg"
155
154
  format="webp"
156
155
  loading="lazy"
157
- fetch-priority="low"
156
+ fetchpriority="low"
158
157
  width="200"
159
158
  height="100"
160
159
  />
@@ -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
@@ -370,7 +370,11 @@ Out of the box, this will enable typed usage of [`navigateTo`](/docs/4.x/api/uti
370
370
  You can even get typed params within a page by using `const route = useRoute('route-name')`.
371
371
 
372
372
  ::important
373
- If you use `pnpm` without `shamefully-hoist=true`, you will need to have `unplugin-vue-router` installed as a devDependency in order for this feature to work.
373
+ If you use `pnpm` without `shamefully-hoist=true`, you will need to add `unplugin-vue-router` as a hoist pattern in your `pnpm-workspace.yaml` in order for this feature to work.
374
+ ```yaml
375
+ publicHoistPattern:
376
+ - "unplugin-vue-router"
377
+ ```
374
378
  ::
375
379
 
376
380
  :video-accordion{title="Watch a video from Daniel Roe explaining type-safe routing in Nuxt" videoId="SXk-L19gTZk"}
@@ -32,7 +32,7 @@ The `build` command creates a `.output` directory with all your application, ser
32
32
  | `--cwd=<directory>` | | Specify the working directory, this takes precedence over ROOTDIR (default: `.`) |
33
33
  | `--logLevel=<silent\|info\|verbose>` | | Specify build-time log level |
34
34
  | `--prerender` | | Build Nuxt and prerender static routes |
35
- | `--preset` | | Nitro server preset |
35
+ | `--preset=<preset>` | | Specify Nitro server preset. Available presets depend on Nitro (e.g. `node-server`, `vercel`, `netlify`, `static`) |
36
36
  | `--dotenv` | | Path to `.env` file to load, relative to the root directory |
37
37
  | `--envName` | | The environment to use when resolving configuration overrides (default is `production` when building, and `development` when running the dev server) |
38
38
  | `-e, --extends=<layer-name>` | | Extend from a Nuxt layer |
@@ -1014,8 +1014,12 @@ Options passed directly to the transformer from `unctx` that preserves async con
1014
1014
 
1015
1015
  Functions to inject a key for.
1016
1016
 
1017
- As long as the number of arguments passed to the function is less than `argumentLength`, an additional magic string will be injected that can be used to deduplicate requests between server and client. You will need to take steps to handle this additional key.
1018
- The key will be unique based on the location of the function being invoked within the file.
1017
+ As long as the number of arguments passed to the function is less than `argumentLength`, an additional magic string will be injected as the last argument. This key is stable between SSR and client-side hydration. You will need to take steps to handle this additional key.
1018
+ The key is unique based on the location of the function being invoked within the file.
1019
+
1020
+ ::read-more{to="/docs/4.x/guide/modules/recipes-basics#add-keyed-functions"}
1021
+ Learn more about keyed functions.
1022
+ ::
1019
1023
 
1020
1024
  - **Type**: `array`
1021
1025
  - **Default**
@@ -1023,31 +1027,38 @@ The key will be unique based on the location of the function being invoked withi
1023
1027
  [
1024
1028
  {
1025
1029
  "name": "callOnce",
1026
- "argumentLength": 3
1030
+ "argumentLength": 3,
1031
+ "source": "#app/composables/once"
1027
1032
  },
1028
1033
  {
1029
1034
  "name": "defineNuxtComponent",
1030
- "argumentLength": 2
1035
+ "argumentLength": 2,
1036
+ "source": "#app/composables/component"
1031
1037
  },
1032
1038
  {
1033
1039
  "name": "useState",
1034
- "argumentLength": 2
1040
+ "argumentLength": 2,
1041
+ "source": "#app/composables/state"
1035
1042
  },
1036
1043
  {
1037
1044
  "name": "useFetch",
1038
- "argumentLength": 3
1045
+ "argumentLength": 3,
1046
+ "source": "#app/composables/fetch"
1039
1047
  },
1040
1048
  {
1041
1049
  "name": "useAsyncData",
1042
- "argumentLength": 3
1050
+ "argumentLength": 3,
1051
+ "source": "#app/composables/asyncData"
1043
1052
  },
1044
1053
  {
1045
1054
  "name": "useLazyAsyncData",
1046
- "argumentLength": 3
1055
+ "argumentLength": 3,
1056
+ "source": "#app/composables/asyncData"
1047
1057
  },
1048
1058
  {
1049
1059
  "name": "useLazyFetch",
1050
- "argumentLength": 3
1060
+ "argumentLength": 3,
1061
+ "source": "#app/composables/fetch"
1051
1062
  }
1052
1063
  ]
1053
1064
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/docs-nightly",
3
- "version": "4.4.0-29506647.0fa65fc3",
3
+ "version": "4.4.0-29532435.dd5ca638",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/nuxt.git",