@nuxt/docs-nightly 4.0.0-29206881.53f2acdc → 4.0.0-29207363.f34c6c24
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.
- package/1.getting-started/18.upgrade.md +76 -82
- package/2.guide/2.directory-structure/1.shared.md +0 -6
- package/2.guide/3.going-further/1.experimental-features.md +11 -10
- package/2.guide/3.going-further/1.features.md +2 -44
- package/3.api/2.composables/use-async-data.md +4 -0
- package/3.api/2.composables/use-fetch.md +4 -0
- package/3.api/5.kit/9.plugins.md +0 -48
- package/3.api/6.nuxt-config.md +2 -35
- package/package.json +1 -1
|
@@ -34,76 +34,37 @@ bun x nuxt upgrade
|
|
|
34
34
|
|
|
35
35
|
To use the latest Nuxt build and test features before their release, read about the [nightly release channel](/docs/guide/going-further/nightly-release-channel) guide.
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
The nightly release channel `latest` tag is currently tracking the Nuxt v4 branch, meaning that it is particularly likely to have breaking changes right now — be careful! You can opt in to the 3.x branch nightly releases with `"nuxt": "npm:nuxt-nightly@3x"`.
|
|
39
|
-
::
|
|
40
|
-
|
|
41
|
-
## Testing Nuxt 4
|
|
37
|
+
## Migrating to Nuxt 4
|
|
42
38
|
|
|
43
|
-
Nuxt 4
|
|
39
|
+
Nuxt 4 includes significant improvements and changes. This guide will help you migrate your existing Nuxt 3 application to Nuxt 4.
|
|
44
40
|
|
|
45
|
-
|
|
41
|
+
First, upgrade to Nuxt 4:
|
|
46
42
|
|
|
47
|
-
|
|
43
|
+
::code-group{sync="pm"}
|
|
48
44
|
|
|
49
|
-
|
|
45
|
+
```bash [npm]
|
|
46
|
+
npm install nuxt@^4.0.0-rc
|
|
47
|
+
```
|
|
50
48
|
|
|
51
|
-
|
|
49
|
+
```bash [yarn]
|
|
50
|
+
yarn add nuxt@^4.0.0-rc
|
|
51
|
+
```
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
```bash [pnpm]
|
|
54
|
+
pnpm add nuxt@^4.0.0-rc
|
|
55
|
+
```
|
|
54
56
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
export default defineNuxtConfig({
|
|
58
|
-
future: {
|
|
59
|
-
compatibilityVersion: 4,
|
|
60
|
-
},
|
|
61
|
-
// To re-enable _all_ Nuxt v3 behavior, set the following options:
|
|
62
|
-
// srcDir: '.',
|
|
63
|
-
// dir: {
|
|
64
|
-
// app: 'app'
|
|
65
|
-
// },
|
|
66
|
-
// experimental: {
|
|
67
|
-
// scanPageMeta: 'after-resolve',
|
|
68
|
-
// sharedPrerenderData: false,
|
|
69
|
-
// compileTemplate: true,
|
|
70
|
-
// resetAsyncDataToUndefined: true,
|
|
71
|
-
// templateUtils: true,
|
|
72
|
-
// relativeWatchPaths: true,
|
|
73
|
-
// normalizeComponentNames: false,
|
|
74
|
-
// spaLoadingTemplateLocation: 'within',
|
|
75
|
-
// parseErrorData: false,
|
|
76
|
-
// pendingWhenIdle: true,
|
|
77
|
-
// alwaysRunFetchOnKeyChange: true,
|
|
78
|
-
// defaults: {
|
|
79
|
-
// useAsyncData: {
|
|
80
|
-
// deep: true
|
|
81
|
-
// }
|
|
82
|
-
// }
|
|
83
|
-
// },
|
|
84
|
-
// features: {
|
|
85
|
-
// inlineStyles: true
|
|
86
|
-
// },
|
|
87
|
-
// unhead: {
|
|
88
|
-
// renderSSRHeadOptions: {
|
|
89
|
-
// omitLineBreaks: false
|
|
90
|
-
// }
|
|
91
|
-
// }
|
|
92
|
-
})
|
|
57
|
+
```bash [bun]
|
|
58
|
+
bun add nuxt@^4.0.0-rc
|
|
93
59
|
```
|
|
94
|
-
::
|
|
95
60
|
|
|
96
|
-
::note
|
|
97
|
-
For now, you need to define the compatibility version in each layer that opts into Nuxt 4 behavior. This will not be required after Nuxt 4 is released.
|
|
98
61
|
::
|
|
99
62
|
|
|
100
|
-
|
|
63
|
+
After upgrading, most Nuxt 4 behaviors are now the default. However, some features can still be configured if you need to maintain backward compatibility during your migration.
|
|
101
64
|
|
|
102
|
-
|
|
65
|
+
The following sections detail the key changes and migrations needed when upgrading to Nuxt 4.
|
|
103
66
|
|
|
104
|
-
|
|
105
|
-
This section is subject to change until the final release, so please check back here regularly if you are testing Nuxt 4 using `compatibilityVersion: 4`.
|
|
106
|
-
::
|
|
67
|
+
Breaking or significant changes are documented below along with migration steps and available configuration options.
|
|
107
68
|
|
|
108
69
|
### Migrating Using Codemods
|
|
109
70
|
|
|
@@ -303,6 +264,64 @@ export default defineNuxtConfig({
|
|
|
303
264
|
})
|
|
304
265
|
```
|
|
305
266
|
|
|
267
|
+
### Corrected Module Loading Order in Layers
|
|
268
|
+
|
|
269
|
+
🚦 **Impact Level**: Minimal
|
|
270
|
+
|
|
271
|
+
#### What Changed
|
|
272
|
+
|
|
273
|
+
The order in which modules are loaded when using [Nuxt layers](/docs/guide/going-further/layers) has been corrected. Previously, modules from the project root were loaded before modules from extended layers, which was the reverse of the expected behavior.
|
|
274
|
+
|
|
275
|
+
Now modules are loaded in the correct order:
|
|
276
|
+
|
|
277
|
+
1. **Layer modules first** (in extend order - deeper layers first)
|
|
278
|
+
2. **Project modules last** (highest priority)
|
|
279
|
+
|
|
280
|
+
This affects both:
|
|
281
|
+
* Modules defined in the `modules` array in `nuxt.config.ts`
|
|
282
|
+
* Auto-discovered modules from the `modules/` directory
|
|
283
|
+
|
|
284
|
+
#### Reasons for Change
|
|
285
|
+
|
|
286
|
+
This change ensures that:
|
|
287
|
+
* Extended layers have lower priority than the consuming project
|
|
288
|
+
* Module execution order matches the intuitive layer inheritance pattern
|
|
289
|
+
* Module configuration and hooks work as expected in multi-layer setups
|
|
290
|
+
|
|
291
|
+
#### Migration Steps
|
|
292
|
+
|
|
293
|
+
**Most projects will not need changes**, as this corrects the loading order to match expected behavior.
|
|
294
|
+
|
|
295
|
+
However, if your project was relying on the previous incorrect order, you may need to:
|
|
296
|
+
|
|
297
|
+
1. **Review module dependencies**: Check if any modules depend on specific loading order
|
|
298
|
+
2. **Adjust module configuration**: If modules were configured to work around the incorrect order
|
|
299
|
+
3. **Test thoroughly**: Ensure all functionality works as expected with the corrected order
|
|
300
|
+
|
|
301
|
+
Example of the new correct order:
|
|
302
|
+
```ts
|
|
303
|
+
// Layer: my-layer/nuxt.config.ts
|
|
304
|
+
export default defineNuxtConfig({
|
|
305
|
+
modules: ['layer-module-1', 'layer-module-2']
|
|
306
|
+
})
|
|
307
|
+
|
|
308
|
+
// Project: nuxt.config.ts
|
|
309
|
+
export default defineNuxtConfig({
|
|
310
|
+
extends: ['./my-layer'],
|
|
311
|
+
modules: ['project-module-1', 'project-module-2']
|
|
312
|
+
})
|
|
313
|
+
|
|
314
|
+
// Loading order (corrected):
|
|
315
|
+
// 1. layer-module-1
|
|
316
|
+
// 2. layer-module-2
|
|
317
|
+
// 3. project-module-1 (can override layer modules)
|
|
318
|
+
// 4. project-module-2 (can override layer modules)
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
If you encounter issues with module order dependencies due to needing to register a hook, consider using the [`modules:done` hook](/docs/guide/going-further/modules#custom-hooks) for modules that need to call a hook. This is run after all other modules have been loaded, which means it is safe to use.
|
|
322
|
+
|
|
323
|
+
👉 See [PR #31507](https://github.com/nuxt/nuxt/pull/31507) and [issue #25719](https://github.com/nuxt/nuxt/issues/25719) for more details.
|
|
324
|
+
|
|
306
325
|
### Deduplication of Route Metadata
|
|
307
326
|
|
|
308
327
|
🚦 **Impact Level**: Minimal
|
|
@@ -490,16 +509,6 @@ Update your custom `error.vue` to remove any additional parsing of `error.data`:
|
|
|
490
509
|
</script>
|
|
491
510
|
```
|
|
492
511
|
|
|
493
|
-
Alternatively, you can disable this change:
|
|
494
|
-
|
|
495
|
-
```ts twoslash [nuxt.config.ts]
|
|
496
|
-
export default defineNuxtConfig({
|
|
497
|
-
experimental: {
|
|
498
|
-
parseErrorData: false
|
|
499
|
-
},
|
|
500
|
-
})
|
|
501
|
-
```
|
|
502
|
-
|
|
503
512
|
### More Granular Inline Styles
|
|
504
513
|
|
|
505
514
|
🚦 **Impact Level**: Moderate
|
|
@@ -697,21 +706,6 @@ If you provide a custom `default` value for `useAsyncData`, this will now be use
|
|
|
697
706
|
|
|
698
707
|
Often users set an appropriately empty value, such as an empty array, to avoid the need to check for `null`/`undefined` when iterating over it. This should be respected when resetting/clearing the data.
|
|
699
708
|
|
|
700
|
-
#### Migration Steps
|
|
701
|
-
|
|
702
|
-
If you encounter any issues you can revert back to the previous behavior, for now, with:
|
|
703
|
-
|
|
704
|
-
```ts twoslash [nuxt.config.ts]
|
|
705
|
-
// @errors: 2353
|
|
706
|
-
export default defineNuxtConfig({
|
|
707
|
-
experimental: {
|
|
708
|
-
resetAsyncDataToUndefined: true,
|
|
709
|
-
}
|
|
710
|
-
})
|
|
711
|
-
```
|
|
712
|
-
|
|
713
|
-
Please report an issue if you are doing so, as we do not plan to keep this as configurable.
|
|
714
|
-
|
|
715
709
|
### Alignment of `pending` value in `useAsyncData` and `useFetch`
|
|
716
710
|
|
|
717
711
|
🚦 **Impact Level**: Medium
|
|
@@ -15,12 +15,6 @@ The `shared/` directory is available in Nuxt v3.14+.
|
|
|
15
15
|
Code in the `shared/` directory cannot import any Vue or Nitro code.
|
|
16
16
|
::
|
|
17
17
|
|
|
18
|
-
::warning
|
|
19
|
-
Auto-imports are not enabled by default in Nuxt v3 to prevent breaking changes in existing projects.
|
|
20
|
-
|
|
21
|
-
To use these auto-imported utils and types, you must first [set `future.compatibilityVersion: 4` in your `nuxt.config.ts`](/docs/getting-started/upgrade#opting-in-to-nuxt-4).
|
|
22
|
-
::
|
|
23
|
-
|
|
24
18
|
:video-accordion{title="Watch a video from Vue School on sharing utils and types between app and server" videoId="nnAR-MO3q5M"}
|
|
25
19
|
|
|
26
20
|
## Usage
|
|
@@ -3,7 +3,7 @@ title: "Experimental Features"
|
|
|
3
3
|
description: "Enable Nuxt experimental features to unlock new possibilities."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
Nuxt includes experimental features that you can enable in your configuration file.
|
|
7
7
|
|
|
8
8
|
Internally, Nuxt uses `@nuxt/schema` to define these experimental features. You can refer to the [API documentation](/docs/api/configuration/nuxt-config#experimental) or the [source code](https://github.com/nuxt/nuxt/blob/main/packages/schema/src/config/experimental.ts) for more information.
|
|
9
9
|
|
|
@@ -284,14 +284,14 @@ export default defineNuxtConfig({
|
|
|
284
284
|
|
|
285
285
|
## sharedPrerenderData
|
|
286
286
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
287
|
+
Nuxt automatically shares payload *data* between pages that are prerendered. This can result in a significant performance improvement when prerendering sites that use `useAsyncData` or `useFetch` and fetch the same data in different pages.
|
|
288
|
+
|
|
289
|
+
You can disable this feature if needed.
|
|
290
290
|
|
|
291
291
|
```ts twoslash [nuxt.config.ts]
|
|
292
292
|
export default defineNuxtConfig({
|
|
293
293
|
experimental: {
|
|
294
|
-
sharedPrerenderData:
|
|
294
|
+
sharedPrerenderData: false
|
|
295
295
|
}
|
|
296
296
|
})
|
|
297
297
|
```
|
|
@@ -332,11 +332,11 @@ globalThis.Buffer = globalThis.Buffer || Buffer
|
|
|
332
332
|
|
|
333
333
|
## scanPageMeta
|
|
334
334
|
|
|
335
|
-
|
|
335
|
+
Nuxt exposing some route metadata defined in `definePageMeta` at build-time to modules (specifically `alias`, `name`, `path`, `redirect`, `props` and `middleware`).
|
|
336
336
|
|
|
337
337
|
This only works with static or strings/arrays rather than variables or conditional assignment. See [original issue](https://github.com/nuxt/nuxt/issues/24770) for more information and context.
|
|
338
338
|
|
|
339
|
-
|
|
339
|
+
By default page metadata is only scanned after all routes have been registered in `pages:extend`. Then another hook, `pages:resolved` will be called.
|
|
340
340
|
|
|
341
341
|
You can disable this feature if it causes issues in your project.
|
|
342
342
|
|
|
@@ -427,13 +427,14 @@ This allows modules to access additional metadata from the page metadata in the
|
|
|
427
427
|
|
|
428
428
|
## normalizeComponentNames
|
|
429
429
|
|
|
430
|
-
|
|
431
|
-
|
|
430
|
+
Nuxt updates auto-generated Vue component names to match the full component name you would use to auto-import the component.
|
|
431
|
+
|
|
432
|
+
If you encounter issues, you can disable this feature.
|
|
432
433
|
|
|
433
434
|
```ts twoslash [nuxt.config.ts]
|
|
434
435
|
export default defineNuxtConfig({
|
|
435
436
|
experimental: {
|
|
436
|
-
normalizeComponentNames:
|
|
437
|
+
normalizeComponentNames: false
|
|
437
438
|
}
|
|
438
439
|
})
|
|
439
440
|
```
|
|
@@ -39,51 +39,9 @@ There is also a `future` namespace for early opting-in to new features that will
|
|
|
39
39
|
|
|
40
40
|
### compatibilityVersion
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
This configuration option is available in Nuxt v3.12+. Please note, that for now, you need to define the compatibility version in each layer that opts into Nuxt 4 behavior. This will not be required after Nuxt 4 is released.
|
|
44
|
-
::
|
|
42
|
+
This is used for enabling early access to Nuxt features or flags.
|
|
45
43
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
Setting `compatibilityVersion` to `4` changes defaults throughout your
|
|
49
|
-
Nuxt configuration to opt-in to Nuxt v4 behaviour, but you can granularly re-enable Nuxt v3 behaviour
|
|
50
|
-
when testing (see example). Please file issues if so, so that we can
|
|
51
|
-
address in Nuxt or in the ecosystem.
|
|
52
|
-
|
|
53
|
-
```ts
|
|
54
|
-
export default defineNuxtConfig({
|
|
55
|
-
future: {
|
|
56
|
-
compatibilityVersion: 4,
|
|
57
|
-
},
|
|
58
|
-
// To re-enable _all_ Nuxt v3 behaviour, set the following options:
|
|
59
|
-
srcDir: '.',
|
|
60
|
-
dir: {
|
|
61
|
-
app: 'app'
|
|
62
|
-
},
|
|
63
|
-
experimental: {
|
|
64
|
-
scanPageMeta: 'after-resolve',
|
|
65
|
-
sharedPrerenderData: false,
|
|
66
|
-
compileTemplate: true,
|
|
67
|
-
resetAsyncDataToUndefined: true,
|
|
68
|
-
templateUtils: true,
|
|
69
|
-
relativeWatchPaths: true,
|
|
70
|
-
normalizeComponentNames: false
|
|
71
|
-
defaults: {
|
|
72
|
-
useAsyncData: {
|
|
73
|
-
deep: true
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
features: {
|
|
78
|
-
inlineStyles: true
|
|
79
|
-
},
|
|
80
|
-
unhead: {
|
|
81
|
-
renderSSRHeadOptions: {
|
|
82
|
-
omitLineBreaks: false
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
})
|
|
86
|
-
```
|
|
44
|
+
It is not configurable yet in Nuxt 4, but once we begin merging breaking changes for v5, it will be possible to enable it.
|
|
87
45
|
|
|
88
46
|
### typescriptBundlerResolution
|
|
89
47
|
|
|
@@ -142,6 +142,10 @@ const { data: users1 } = useAsyncData('users', () => $fetch('/api/users'), { imm
|
|
|
142
142
|
const { data: users2 } = useAsyncData('users', () => $fetch('/api/users'), { immediate: false })
|
|
143
143
|
```
|
|
144
144
|
|
|
145
|
+
::tip
|
|
146
|
+
Keyed state created using `useAsyncData` can be retrieved across your Nuxt application using [`useNuxtData`](/docs/api/composables/use-nuxt-data).
|
|
147
|
+
::
|
|
148
|
+
|
|
145
149
|
## Return Values
|
|
146
150
|
|
|
147
151
|
- `data`: the result of the asynchronous function that is passed in.
|
|
@@ -82,6 +82,10 @@ const { data: post } = await useFetch(() => `/api/posts/${id.value}`)
|
|
|
82
82
|
|
|
83
83
|
When using `useFetch` with the same URL and options in multiple components, they will share the same `data`, `error` and `status` refs. This ensures consistency across components.
|
|
84
84
|
|
|
85
|
+
::tip
|
|
86
|
+
Keyed state created using `useFetch` can be retrieved across your Nuxt application using [`useNuxtData`](/docs/api/composables/use-nuxt-data).
|
|
87
|
+
::
|
|
88
|
+
|
|
85
89
|
::warning
|
|
86
90
|
`useFetch` is a reserved function name transformed by the compiler, so you should not name your own function `useFetch`.
|
|
87
91
|
::
|
package/3.api/5.kit/9.plugins.md
CHANGED
|
@@ -214,51 +214,3 @@ export default defineNuxtPlugin({
|
|
|
214
214
|
```
|
|
215
215
|
|
|
216
216
|
::
|
|
217
|
-
|
|
218
|
-
#### Using an EJS template to generate a plugin
|
|
219
|
-
|
|
220
|
-
You can also use an EJS template to generate your plugin. Options can be passed through the `options` property and then used within the EJS template to generate the plugin content.
|
|
221
|
-
|
|
222
|
-
::code-group
|
|
223
|
-
|
|
224
|
-
```ts [module.ts]
|
|
225
|
-
import { addPluginTemplate, createResolver, defineNuxtModule } from '@nuxt/kit'
|
|
226
|
-
|
|
227
|
-
export default defineNuxtModule({
|
|
228
|
-
setup (options, nuxt) {
|
|
229
|
-
const { resolve } = createResolver(import.meta.url)
|
|
230
|
-
|
|
231
|
-
addPluginTemplate({
|
|
232
|
-
src: resolve('templates/plugin.ejs'),
|
|
233
|
-
filename: 'plugin.mjs',
|
|
234
|
-
options: {
|
|
235
|
-
ssr: nuxt.options.ssr,
|
|
236
|
-
},
|
|
237
|
-
})
|
|
238
|
-
},
|
|
239
|
-
})
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
```ts [templates/plugin.ejs]
|
|
243
|
-
import { VueFire, useSSRInitialState } from 'vuefire'
|
|
244
|
-
import { defineNuxtPlugin } from '#imports'
|
|
245
|
-
|
|
246
|
-
export default defineNuxtPlugin((nuxtApp) => {
|
|
247
|
-
const firebaseApp = nuxtApp.$firebaseApp
|
|
248
|
-
nuxtApp.vueApp.use(VueFire, { firebaseApp })
|
|
249
|
-
|
|
250
|
-
<% if(options.ssr) { %>
|
|
251
|
-
if (import.meta.server) {
|
|
252
|
-
nuxtApp.payload.vuefire = useSSRInitialState(undefined, firebaseApp)
|
|
253
|
-
} else if (nuxtApp.payload?.vuefire) {
|
|
254
|
-
useSSRInitialState(nuxtApp.payload.vuefire, firebaseApp)
|
|
255
|
-
}
|
|
256
|
-
<% } %>
|
|
257
|
-
})
|
|
258
|
-
```
|
|
259
|
-
|
|
260
|
-
::
|
|
261
|
-
|
|
262
|
-
::warning
|
|
263
|
-
If you set `compatibilityVersion` to `4`, Nuxt no longer uses `lodash.template` to compile templates by default. You can still enable it via the `experimental.compileTemplate` option, but support for EJS templates will be removed entirely in the next major version.
|
|
264
|
-
::
|
package/3.api/6.nuxt-config.md
CHANGED
|
@@ -1281,42 +1281,9 @@ If set to 'production' or `true`, JS will be disabled in production mode only.
|
|
|
1281
1281
|
|
|
1282
1282
|
### `compatibilityVersion`
|
|
1283
1283
|
|
|
1284
|
-
|
|
1284
|
+
This is used for enabling early access to Nuxt features or flags.
|
|
1285
1285
|
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
- **Type**: `number`
|
|
1289
|
-
- **Default:** `3`
|
|
1290
|
-
|
|
1291
|
-
**Example**:
|
|
1292
|
-
```ts
|
|
1293
|
-
export default defineNuxtConfig({
|
|
1294
|
-
future: {
|
|
1295
|
-
compatibilityVersion: 4,
|
|
1296
|
-
},
|
|
1297
|
-
// To re-enable _all_ Nuxt v3 behaviour, set the following options:
|
|
1298
|
-
srcDir: '.',
|
|
1299
|
-
dir: {
|
|
1300
|
-
app: 'app'
|
|
1301
|
-
},
|
|
1302
|
-
experimental: {
|
|
1303
|
-
compileTemplate: true,
|
|
1304
|
-
templateUtils: true,
|
|
1305
|
-
relativeWatchPaths: true,
|
|
1306
|
-
resetAsyncDataToUndefined: true,
|
|
1307
|
-
defaults: {
|
|
1308
|
-
useAsyncData: {
|
|
1309
|
-
deep: true
|
|
1310
|
-
}
|
|
1311
|
-
}
|
|
1312
|
-
},
|
|
1313
|
-
unhead: {
|
|
1314
|
-
renderSSRHeadOptions: {
|
|
1315
|
-
omitLineBreaks: false
|
|
1316
|
-
}
|
|
1317
|
-
}
|
|
1318
|
-
})
|
|
1319
|
-
```
|
|
1286
|
+
It is not configurable yet in Nuxt 4, but once we begin merging breaking changes for v5, it will be possible to enable it.
|
|
1320
1287
|
|
|
1321
1288
|
### `multiApp`
|
|
1322
1289
|
|