@nuxt/docs-nightly 4.5.1-29752449.30d24817 → 4.5.2-2610052030-052d82e
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/01.introduction.md +8 -8
- package/1.getting-started/02.installation.md +2 -4
- package/1.getting-started/03.configuration.md +16 -16
- package/1.getting-started/04.views.md +8 -8
- package/1.getting-started/05.assets.md +10 -10
- package/1.getting-started/06.styling.md +10 -10
- package/1.getting-started/07.routing.md +15 -15
- package/1.getting-started/08.seo-meta.md +15 -15
- package/1.getting-started/09.transitions.md +10 -10
- package/1.getting-started/10.data-fetching.md +61 -47
- package/1.getting-started/11.state-management.md +11 -11
- package/1.getting-started/12.error-handling.md +20 -18
- package/1.getting-started/13.server.md +7 -7
- package/1.getting-started/14.layers.md +6 -6
- package/1.getting-started/15.prerendering.md +22 -28
- package/1.getting-started/16.deployment.md +22 -6
- package/1.getting-started/17.testing.md +200 -21
- package/1.getting-started/18.upgrade.md +78 -278
- package/2.directory-structure/0.nuxt.md +2 -2
- package/2.directory-structure/0.output.md +3 -3
- package/2.directory-structure/1.app/1.assets.md +3 -3
- package/2.directory-structure/1.app/1.components.md +26 -109
- package/2.directory-structure/1.app/1.composables.md +5 -5
- package/2.directory-structure/1.app/1.layouts.md +10 -10
- package/2.directory-structure/1.app/1.middleware.md +14 -10
- package/2.directory-structure/1.app/1.pages.md +25 -20
- package/2.directory-structure/1.app/1.plugins.md +7 -7
- package/2.directory-structure/1.app/1.utils.md +9 -5
- package/2.directory-structure/1.app/3.app-config.md +7 -7
- package/2.directory-structure/1.app/3.app.md +6 -6
- package/2.directory-structure/1.app/3.error.md +1 -1
- package/2.directory-structure/1.content.md +1 -1
- package/2.directory-structure/1.layers.md +13 -13
- package/2.directory-structure/1.modules.md +3 -3
- package/2.directory-structure/1.node_modules.md +1 -1
- package/2.directory-structure/1.server.md +33 -14
- package/2.directory-structure/1.shared.md +7 -5
- package/2.directory-structure/1.test.md +25 -0
- package/2.directory-structure/2.env.md +7 -7
- package/2.directory-structure/2.nuxtignore.md +3 -3
- package/2.directory-structure/2.nuxtrc.md +3 -3
- package/2.directory-structure/3.nuxt-config.md +2 -2
- package/2.directory-structure/3.tsconfig.md +21 -11
- package/2.directory-structure/index.md +29 -25
- package/3.guide/0.index.md +6 -6
- package/3.guide/1.concepts/1.rendering.md +76 -12
- package/3.guide/1.concepts/10.vuejs-development.md +73 -8
- package/3.guide/1.concepts/2.nuxt-lifecycle.md +18 -18
- package/3.guide/1.concepts/3.auto-imports.md +11 -11
- package/3.guide/1.concepts/4.server-engine.md +6 -6
- package/3.guide/1.concepts/5.modules.md +4 -4
- package/3.guide/1.concepts/6.server-components.md +198 -0
- package/3.guide/1.concepts/7.esm.md +5 -5
- package/3.guide/1.concepts/8.typescript.md +9 -9
- package/3.guide/2.best-practices/accessibility.md +155 -0
- package/3.guide/2.best-practices/hydration.md +5 -5
- package/3.guide/2.best-practices/performance.md +13 -9
- package/3.guide/3.ai/1.mcp.md +104 -19
- package/3.guide/4.modules/2.module-anatomy.md +5 -5
- package/3.guide/4.modules/3.recipes-basics.md +8 -8
- package/3.guide/4.modules/4.module-dependencies.md +1 -1
- package/3.guide/4.modules/5.recipes-advanced.md +6 -8
- package/3.guide/4.modules/6.testing.md +2 -2
- package/3.guide/4.modules/7.best-practices.md +2 -2
- package/3.guide/4.modules/9.server-compatibility.md +215 -0
- package/3.guide/4.modules/index.md +9 -9
- package/3.guide/5.recipes/1.custom-routing.md +15 -11
- package/3.guide/5.recipes/2.vite-plugin.md +3 -3
- package/3.guide/5.recipes/3.custom-usefetch.md +5 -5
- package/3.guide/5.recipes/4.sessions-and-authentication.md +2 -2
- package/3.guide/5.recipes/5.mostly-static-sites.md +127 -0
- package/3.guide/6.going-further/1.events.md +1 -1
- package/3.guide/6.going-further/1.experimental-features.md +254 -22
- package/3.guide/6.going-further/1.features.md +42 -6
- package/3.guide/6.going-further/1.internals.md +10 -10
- package/3.guide/6.going-further/10.runtime-config.md +28 -6
- package/3.guide/6.going-further/11.nightly-release-channel.md +1 -1
- package/3.guide/6.going-further/2.hooks.md +6 -6
- package/3.guide/6.going-further/4.kit.md +4 -4
- package/3.guide/6.going-further/5.server-imports.md +221 -0
- package/3.guide/6.going-further/6.nuxt-app.md +7 -7
- package/3.guide/6.going-further/7.layers.md +13 -13
- package/3.guide/6.going-further/8.builders.md +38 -14
- package/4.api/1.components/1.nuxt-client-fallback.md +1 -1
- package/4.api/1.components/10.nuxt-picture.md +1 -1
- package/4.api/1.components/11.teleports.md +1 -1
- package/4.api/1.components/12.nuxt-route-announcer.md +5 -3
- package/4.api/1.components/14.nuxt-announcer.md +3 -3
- package/4.api/1.components/2.nuxt-page.md +5 -5
- package/4.api/1.components/3.nuxt-layout.md +8 -8
- package/4.api/1.components/4.nuxt-link.md +6 -4
- package/4.api/1.components/5.nuxt-loading-indicator.md +3 -3
- package/4.api/1.components/6.nuxt-error-boundary.md +1 -1
- package/4.api/1.components/8.nuxt-island.md +5 -5
- package/4.api/2.composables/create-use-async-data.md +51 -8
- package/4.api/2.composables/create-use-fetch.md +126 -9
- package/4.api/2.composables/use-announcer.md +3 -3
- package/4.api/2.composables/use-app-config.md +1 -1
- package/4.api/2.composables/use-async-data.md +19 -11
- package/4.api/2.composables/use-cookie.md +22 -6
- package/4.api/2.composables/use-error.md +1 -1
- package/4.api/2.composables/use-fetch.md +14 -10
- package/4.api/2.composables/use-head-safe.md +2 -2
- package/4.api/2.composables/use-head.md +2 -2
- package/4.api/2.composables/use-hydration.md +1 -1
- package/4.api/2.composables/use-layout.md +1 -1
- package/4.api/2.composables/use-lazy-async-data.md +8 -8
- package/4.api/2.composables/use-lazy-fetch.md +11 -11
- package/4.api/2.composables/use-loading-indicator.md +2 -2
- package/4.api/2.composables/use-nuxt-app.md +13 -13
- package/4.api/2.composables/use-nuxt-data.md +1 -1
- package/4.api/2.composables/use-preview-mode.md +3 -3
- package/4.api/2.composables/use-request-event.md +29 -3
- package/4.api/2.composables/use-request-fetch.md +2 -2
- package/4.api/2.composables/use-request-header.md +1 -1
- package/4.api/2.composables/use-request-headers.md +1 -1
- package/4.api/2.composables/use-request-url.md +1 -1
- package/4.api/2.composables/use-response-header.md +2 -2
- package/4.api/2.composables/use-route-announcer.md +4 -2
- package/4.api/2.composables/use-route.md +2 -2
- package/4.api/2.composables/use-router.md +5 -5
- package/4.api/2.composables/use-runtime-config.md +5 -5
- package/4.api/2.composables/use-runtime-hook.md +1 -1
- package/4.api/2.composables/use-seo-meta.md +3 -3
- package/4.api/2.composables/use-server-seo-meta.md +5 -5
- package/4.api/2.composables/use-state.md +4 -4
- package/4.api/3.utils/$fetch.md +5 -5
- package/4.api/3.utils/abort-navigation.md +1 -1
- package/4.api/3.utils/add-route-middleware.md +2 -2
- package/4.api/3.utils/call-once.md +3 -3
- package/4.api/3.utils/clear-error.md +2 -2
- package/4.api/3.utils/clear-nuxt-data.md +1 -1
- package/4.api/3.utils/clear-nuxt-state.md +2 -2
- package/4.api/3.utils/create-error.md +19 -1
- package/4.api/3.utils/define-nuxt-plugin.md +2 -2
- package/4.api/3.utils/define-nuxt-route-middleware.md +3 -3
- package/4.api/3.utils/define-page-meta.md +12 -12
- package/4.api/3.utils/define-route-rules.md +4 -4
- package/4.api/3.utils/define-use-async-data-addon.md +57 -0
- package/4.api/3.utils/define-use-fetch-addon.md +168 -0
- package/4.api/3.utils/navigate-to.md +6 -2
- package/4.api/3.utils/prefetch-components.md +1 -1
- package/4.api/3.utils/preload-route-components.md +2 -2
- package/4.api/3.utils/prerender-routes.md +3 -3
- package/4.api/3.utils/refresh-cookie.md +1 -1
- package/4.api/3.utils/refresh-nuxt-data.md +3 -3
- package/4.api/3.utils/reload-nuxt-app.md +1 -1
- package/4.api/3.utils/set-page-layout.md +1 -1
- package/4.api/3.utils/set-response-status.md +2 -2
- package/4.api/3.utils/show-error.md +3 -3
- package/4.api/3.utils/update-app-config.md +2 -2
- package/4.api/4.commands/README.md +9 -0
- package/4.api/5.kit/1.modules.md +3 -3
- package/4.api/5.kit/10.runtime-config.md +1 -1
- package/4.api/5.kit/10.templates.md +42 -0
- package/4.api/5.kit/12.nitro.md +59 -18
- package/4.api/5.kit/14.logging.md +56 -2
- package/4.api/5.kit/15.builder.md +1 -1
- package/4.api/5.kit/18.dependencies.md +90 -0
- package/4.api/5.kit/2.programmatic.md +78 -1
- package/4.api/5.kit/3.compatibility.md +2 -2
- package/4.api/5.kit/4.autoimports.md +13 -13
- package/4.api/5.kit/5.components.md +3 -3
- package/4.api/5.kit/6.context.md +2 -2
- package/4.api/5.kit/7.pages.md +35 -4
- package/4.api/5.kit/8.layout.md +1 -1
- package/4.api/6.advanced/1.hooks.md +6 -3
- package/4.api/6.nuxt-config.md +44 -21
- package/4.api/index.md +7 -7
- package/5.community/2.getting-help.md +1 -1
- package/5.community/3.reporting-bugs.md +1 -1
- package/5.community/4.contribution.md +14 -12
- package/5.community/5.framework-contribution.md +4 -4
- package/5.community/6.roadmap.md +6 -6
- package/6.bridge/1.overview.md +12 -12
- package/6.bridge/2.typescript.md +1 -1
- package/6.bridge/3.bridge-composition-api.md +6 -6
- package/6.bridge/4.plugins-and-middleware.md +4 -4
- package/6.bridge/5.nuxt3-compatible-api.md +9 -9
- package/6.bridge/6.meta.md +5 -5
- package/6.bridge/7.runtime-config.md +1 -1
- package/6.bridge/8.nitro.md +1 -1
- package/6.bridge/9.vite.md +1 -1
- package/7.migration/1.overview.md +2 -2
- package/7.migration/10.bundling.md +1 -1
- package/7.migration/11.server.md +3 -3
- package/7.migration/2.configuration.md +6 -6
- package/7.migration/20.module-authors.md +7 -7
- package/7.migration/3.auto-imports.md +3 -3
- package/7.migration/4.meta.md +4 -4
- package/7.migration/5.plugins-and-middleware.md +3 -3
- package/7.migration/6.pages-and-layouts.md +13 -13
- package/7.migration/7.component-options.md +15 -15
- package/7.migration/8.runtime-config.md +4 -4
- package/README.md +1 -1
- package/errors/e8007.md +28 -0
- package/package.json +2 -2
- package/4.api/4.commands/.navigation.yml +0 -3
- package/4.api/4.commands/add.md +0 -112
- package/4.api/4.commands/analyze.md +0 -42
- package/4.api/4.commands/build-module.md +0 -42
- package/4.api/4.commands/build.md +0 -48
- package/4.api/4.commands/cleanup.md +0 -38
- package/4.api/4.commands/dev.md +0 -61
- package/4.api/4.commands/devtools.md +0 -38
- package/4.api/4.commands/generate.md +0 -43
- package/4.api/4.commands/info.md +0 -33
- package/4.api/4.commands/init.md +0 -50
- package/4.api/4.commands/module.md +0 -84
- package/4.api/4.commands/prepare.md +0 -41
- package/4.api/4.commands/preview.md +0 -44
- package/4.api/4.commands/test.md +0 -40
- package/4.api/4.commands/typecheck.md +0 -44
- package/4.api/4.commands/upgrade.md +0 -37
|
@@ -36,17 +36,11 @@ deno x nuxt upgrade
|
|
|
36
36
|
|
|
37
37
|
### Nightly Release Channel
|
|
38
38
|
|
|
39
|
-
To use the latest Nuxt build and test features before their release, read about the [nightly release channel](/docs/
|
|
39
|
+
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.
|
|
40
40
|
|
|
41
41
|
## Testing Nuxt 5
|
|
42
42
|
|
|
43
|
-
Nuxt 5 is **currently in development**.
|
|
44
|
-
|
|
45
|
-
### Opting in to Nuxt 5
|
|
46
|
-
|
|
47
|
-
First, upgrade Nuxt to the [latest release](https://github.com/nuxt/nuxt/releases).
|
|
48
|
-
|
|
49
|
-
Then you can set your `future.compatibilityVersion` to match Nuxt 5 behavior:
|
|
43
|
+
Nuxt 5 is **currently in development**. From Nuxt 4.2+ you can test many of its breaking changes by setting `future.compatibilityVersion` to `5`:
|
|
50
44
|
|
|
51
45
|
```ts twoslash [nuxt.config.ts]
|
|
52
46
|
export default defineNuxtConfig({
|
|
@@ -56,287 +50,93 @@ export default defineNuxtConfig({
|
|
|
56
50
|
})
|
|
57
51
|
```
|
|
58
52
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
- **Vite Environment API**:
|
|
62
|
-
- **
|
|
63
|
-
-
|
|
64
|
-
- **
|
|
65
|
-
- **
|
|
66
|
-
-
|
|
67
|
-
- **
|
|
68
|
-
-
|
|
53
|
+
Defaults throughout your Nuxt configuration then change to opt in to Nuxt 5 behaviour. On Nuxt 4 this covers:
|
|
54
|
+
|
|
55
|
+
- **Vite Environment API**: [`experimental.viteEnvironmentApi`](/docs/guide/going-further/experimental-features#viteenvironmentapi) is enabled, changing how Vite plugins are registered and configured
|
|
56
|
+
- **Case-sensitive routing**: page routes match URL casing exactly, consistent with Nitro, so `/About` no longer matches `pages/about.vue`
|
|
57
|
+
- **Normalized page names**: page component names [match their route names](/docs/guide/going-further/experimental-features#normalizepagenames) for consistent `<KeepAlive>` behaviour
|
|
58
|
+
- **Serializable page meta**: [`experimental.extractSerializablePageMeta`](/docs/guide/going-further/experimental-features#extractserializablepagemeta) extracts statically analysable `definePageMeta` values at build time
|
|
59
|
+
- **Client-side payload extraction**: [`experimental.payloadExtraction`](/docs/guide/going-further/experimental-features#payloadextraction) becomes `'client'`, inlining the payload in the HTML of a prerendered page
|
|
60
|
+
- **`clearNuxtState` resets to defaults**: `clearNuxtState` resets state to the initial value of [`useState`](/docs/api/composables/use-state) instead of setting it to `undefined`
|
|
61
|
+
- **Non-async `callHook`**: `callHook` may return `void` instead of always returning a `Promise`
|
|
62
|
+
- **Early return from `navigateTo`**: [`experimental.navigateToEarlyReturn`](/docs/guide/going-further/experimental-features#navigatetoearlyreturn) stops a middleware continuing after it redirects
|
|
63
|
+
- **Server-only head composables**: `useServerHead`, `useServerHeadSafe` and `useServerSeoMeta` are no longer auto-imported, `unhead.legacy` is ignored, Unhead's legacy plugins are no longer registered and Capo sorting is always on
|
|
64
|
+
- **PostCSS defaults off**: `autoprefixer` and `cssnano` are no longer configured unless you enable them in `postcss.plugins`
|
|
65
|
+
- **Keyed composables require `source`**: a [`optimization.keyedComposables`](/docs/api/nuxt-config#keyedcomposables) entry without a string `source` is no longer matched through its auto-import
|
|
66
|
+
- **Comment node placeholders**: client-only components use [comment nodes instead of `<div>`](/docs/guide/going-further/experimental-features#clientnodeplaceholder) as SSR placeholders
|
|
67
|
+
- **Typed pages**: [`experimental.typedPages`](/docs/guide/going-further/experimental-features#typedpages) is enabled for type-checked routing
|
|
68
|
+
- **Error response format**: `experimental.inlineErrorRendering` is enabled, so page errors return the error page and server route errors return JSON, [regardless of the request headers](https://nuxt.com/docs/5.x/getting-started/upgrade#error-format-depends-on-where-the-error-is-thrown)
|
|
69
|
+
- **Typed `$fetch`**: [`experimental.routeTypedFetch`](/docs/guide/going-further/experimental-features#routetypedfetch) types `$fetch` and `useFetch` from the generated route types
|
|
70
|
+
- **Nitro auto-imports off**: server code imports Nitro's helpers explicitly rather than relying on the auto-import compatibility layer
|
|
71
|
+
- **Vue Options API disabled**: the Options API is compiled out of the client bundle to reduce its size
|
|
72
|
+
- **Stricter side-effect imports**: the generated `tsconfig.json` enables `noUncheckedSideEffectImports`
|
|
73
|
+
- **TypeScript `baseUrl` ignored**: generated TypeScript configurations no longer use `compilerOptions.baseUrl` to resolve Nuxt aliases
|
|
69
74
|
|
|
70
75
|
::note
|
|
71
|
-
This
|
|
76
|
+
This list describes what the flag changes on Nuxt 4. Nuxt 5 itself carries further changes that no flag enables here, such as the upgrade to Nitro v3.
|
|
72
77
|
::
|
|
73
78
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
### Migration to Vite Environment API
|
|
79
|
+
The migration steps for each change, and everything else the upgrade brings, are documented in the [Nuxt 5 upgrade guide](https://nuxt.com/docs/5.x/getting-started/upgrade).
|
|
77
80
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
#### What Changed
|
|
81
|
+
## Moving to `nuxt/server`
|
|
81
82
|
|
|
82
|
-
Nuxt
|
|
83
|
+
From Nuxt 4.6, server code can import its handler and helpers from [`nuxt/server`](/docs/guide/going-further/server-imports) rather than from h3, so the same file runs on Nuxt 4 (`nitropack` v2 and h3 v1) and on [Nuxt 5](https://nuxt.com/docs/5.x/getting-started/upgrade) (Nitro v3 and h3 v2).
|
|
83
84
|
|
|
84
|
-
|
|
85
|
+
On Nuxt 4.6, import `defineEventHandler` and the helpers from `nuxt/server` explicitly. The auto-imported names of the same spelling are h3 v1's, and h3's `defineEventHandler` passes your handler a different event from the one the `nuxt/server` helpers read.
|
|
85
86
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
2. **Changed plugin registration**: Vite plugins registered with `addVitePlugin()` and only targeting one environment (by passing `server: false` or `client: false`) will not have their `config` or `configResolved` hooks called.
|
|
95
|
-
|
|
96
|
-
3. **Shared configuration**: The `vite:extendConfig` and `vite:configResolved` hooks now work with a shared configuration rather than separate client/server configs.
|
|
97
|
-
|
|
98
|
-
#### Reasons for Change
|
|
99
|
-
|
|
100
|
-
The Vite Environment API provides:
|
|
101
|
-
- Better consistency between development and production builds
|
|
102
|
-
- More granular control over environment-specific configuration
|
|
103
|
-
- Improved performance and plugin architecture
|
|
104
|
-
- Support for custom environments beyond just client and server
|
|
105
|
-
|
|
106
|
-
#### Migration Steps
|
|
107
|
-
|
|
108
|
-
##### 1. Migrate to use Vite plugins
|
|
109
|
-
|
|
110
|
-
We would recommend you use a Vite plugin instead of `extendViteConfig`, `vite:configResolved` and `vite:extendConfig`.
|
|
111
|
-
|
|
112
|
-
```ts
|
|
113
|
-
// Before
|
|
114
|
-
extendViteConfig((config) => {
|
|
115
|
-
config.optimizeDeps.include.push('my-package')
|
|
116
|
-
}, { server: false })
|
|
117
|
-
|
|
118
|
-
nuxt.hook('vite:extendConfig' /* or vite:configResolved */, (config, { isClient }) => {
|
|
119
|
-
if (isClient) {
|
|
120
|
-
config.optimizeDeps.include.push('my-package')
|
|
121
|
-
}
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
// After
|
|
125
|
-
addVitePlugin(() => ({
|
|
126
|
-
name: 'my-plugin',
|
|
127
|
-
config (config) {
|
|
128
|
-
// you can set global vite configuration here
|
|
129
|
-
},
|
|
130
|
-
configResolved (config) {
|
|
131
|
-
// you can access the fully resolved vite configuration here
|
|
132
|
-
},
|
|
133
|
-
configEnvironment (name, config) {
|
|
134
|
-
// you can set environment-specific vite configuration here
|
|
135
|
-
if (name === 'client') {
|
|
136
|
-
config.optimizeDeps ||= {}
|
|
137
|
-
config.optimizeDeps.include ||= []
|
|
138
|
-
config.optimizeDeps.include.push('my-package')
|
|
139
|
-
}
|
|
140
|
-
},
|
|
141
|
-
applyToEnvironment (environment) {
|
|
142
|
-
return environment.name === 'client'
|
|
143
|
-
},
|
|
144
|
-
}))
|
|
87
|
+
```diff [server/api/hello.ts]
|
|
88
|
+
+ import { defineEventHandler, getQuery } from 'nuxt/server'
|
|
89
|
+
+
|
|
90
|
+
export default defineEventHandler((event) => {
|
|
91
|
+
const { name } = getQuery<{ name?: string }>(event)
|
|
92
|
+
return { message: `Hello, ${name ?? 'world'}!` }
|
|
93
|
+
})
|
|
145
94
|
```
|
|
146
95
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
})
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
::read-more{to="https://vite.dev/guide/api-environment" target="_blank"}
|
|
184
|
-
Learn more about Vite's Environment API
|
|
185
|
-
::
|
|
186
|
-
|
|
187
|
-
### Non-Async `callHook`
|
|
188
|
-
|
|
189
|
-
🚦 **Impact Level**: Minimal
|
|
190
|
-
|
|
191
|
-
#### What Changed
|
|
192
|
-
|
|
193
|
-
With the upgrade to [hookable v6](https://github.com/unjs/hookable), `callHook` may now return `void` instead of always returning `Promise<void>`. This is a significant performance improvement that avoids unnecessary `Promise` allocations when there are no registered hooks or all hooks are synchronous.
|
|
194
|
-
|
|
195
|
-
By default (with `compatibilityVersion: 4`), Nuxt wraps `callHook` with `Promise.resolve()` so that existing `.then()` and `.catch()` chaining continues to work. With `compatibilityVersion: 5`, this wrapper is removed.
|
|
196
|
-
|
|
197
|
-
::tip
|
|
198
|
-
This affects both build-time Nuxt hooks (used by Nuxt modules) and runtime Nuxt hooks (which you might use in your application code).
|
|
199
|
-
::
|
|
200
|
-
|
|
201
|
-
#### Reasons for Change
|
|
202
|
-
|
|
203
|
-
Hookable v6's `callHook` is 20-40x faster because it avoids creating a `Promise` when one is not needed. This benefits applications with many hook call sites.
|
|
204
|
-
|
|
205
|
-
#### Migration Steps
|
|
206
|
-
|
|
207
|
-
If you or your modules use `callHook` with `.then()` or `.catch()` chaining, switch to `await`:
|
|
208
|
-
|
|
209
|
-
```diff
|
|
210
|
-
- nuxtApp.callHook('my:hook', data).then(() => { ... })
|
|
211
|
-
+ await nuxtApp.callHook('my:hook', data)
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
```diff
|
|
215
|
-
- nuxtApp.hooks.callHook('my:hook', data).catch(err => { ... })
|
|
216
|
-
+ try { await nuxtApp.hooks.callHook('my:hook', data) } catch (err) { ... }
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
::tip
|
|
220
|
-
You can test this feature early by setting `future.compatibilityVersion: 5` (see [Testing Nuxt 5](/docs/4.x/getting-started/upgrade#testing-nuxt-5)) or by enabling it explicitly with `experimental.asyncCallHook: false`.
|
|
221
|
-
::
|
|
222
|
-
|
|
223
|
-
Alternatively, you can ensure `callHook` always returns a `Promise` with:
|
|
224
|
-
|
|
225
|
-
```ts twoslash [nuxt.config.ts]
|
|
226
|
-
export default defineNuxtConfig({
|
|
227
|
-
experimental: {
|
|
228
|
-
asyncCallHook: true,
|
|
229
|
-
},
|
|
230
|
-
})
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
### Client-Only Comment Placeholders
|
|
234
|
-
|
|
235
|
-
🚦 **Impact Level**: Minimal
|
|
236
|
-
|
|
237
|
-
#### What Changed
|
|
238
|
-
|
|
239
|
-
With `compatibilityVersion: 5`, client-only components (`.client.vue` files and `createClientOnly()` wrappers) now render an HTML comment (`<!--placeholder-->`) on the server instead of an empty `<div>` element.
|
|
240
|
-
|
|
241
|
-
#### Reasons for Change
|
|
242
|
-
|
|
243
|
-
When the placeholder `<div>` and the actual component root share the same tag name, Vue's runtime skips re-applying `setScopeId` during hydration. This causes scoped styles to be missing after the component mounts. Using a comment node avoids the tag name collision entirely.
|
|
244
|
-
|
|
245
|
-
#### Migration Steps
|
|
246
|
-
|
|
247
|
-
If you rely on the placeholder `<div>` to inherit attributes (`class`, `style`, etc.) for layout purposes (e.g., reserving space to prevent layout shift), wrap the component in `<ClientOnly>` with a `#fallback` slot instead:
|
|
248
|
-
|
|
249
|
-
```diff
|
|
250
|
-
- <MyComponent class="placeholder" style="min-height: 200px" />
|
|
251
|
-
+ <ClientOnly>
|
|
252
|
-
+ <MyComponent />
|
|
253
|
-
+ <template #fallback>
|
|
254
|
-
+ <div class="placeholder" style="min-height: 200px"></div>
|
|
255
|
-
+ </template>
|
|
256
|
-
+ </ClientOnly>
|
|
257
|
-
```
|
|
258
|
-
|
|
259
|
-
::tip
|
|
260
|
-
You can test this feature early by setting `future.compatibilityVersion: 5` (see [Testing Nuxt 5](/docs/4.x/getting-started/upgrade#testing-nuxt-5)) or by enabling it explicitly with `experimental.clientNodePlaceholder: true`.
|
|
261
|
-
::
|
|
262
|
-
|
|
263
|
-
Alternatively, you can revert to the previous `<div>` placeholder behavior with:
|
|
264
|
-
|
|
265
|
-
```ts twoslash [nuxt.config.ts]
|
|
266
|
-
export default defineNuxtConfig({
|
|
267
|
-
experimental: {
|
|
268
|
-
clientNodePlaceholder: false,
|
|
269
|
-
},
|
|
270
|
-
})
|
|
271
|
-
```
|
|
272
|
-
|
|
273
|
-
### Stricter Side-Effect Imports
|
|
274
|
-
|
|
275
|
-
🚦 **Impact Level**: Minimal
|
|
276
|
-
|
|
277
|
-
#### What Changed
|
|
278
|
-
|
|
279
|
-
With `compatibilityVersion: 5`, Nuxt's generated `tsconfig.json` enables [`noUncheckedSideEffectImports`](https://www.typescriptlang.org/tsconfig/#noUncheckedSideEffectImports). This is a default in TypeScript 7, so adopting it early keeps your project aligned ahead of that upgrade.
|
|
280
|
-
|
|
281
|
-
With this option on, a side-effect-only import (`import './setup'`) that TypeScript cannot resolve to a module is now a type error, whereas it was previously ignored. This only affects type-checking (`nuxt typecheck` and your editor), not runtime behavior.
|
|
282
|
-
|
|
283
|
-
#### Reasons for Change
|
|
284
|
-
|
|
285
|
-
Unresolved side-effect imports were silently ignored, so a typo or a deleted file could pass type-checking. Flagging them catches these mistakes and matches the TypeScript 7 default.
|
|
286
|
-
|
|
287
|
-
#### Migration Steps
|
|
288
|
-
|
|
289
|
-
If type-checking now errors on a side-effect import of a non-code asset (for example `import '~/assets/styles.css'`), add an ambient module declaration so TypeScript knows the import is valid:
|
|
290
|
-
|
|
291
|
-
```ts [types.d.ts]
|
|
292
|
-
declare module '*.css' {}
|
|
293
|
-
```
|
|
294
|
-
|
|
295
|
-
::tip
|
|
296
|
-
You can revert to the previous behavior by disabling the option in your `nuxt.config`:
|
|
297
|
-
|
|
298
|
-
<!-- @case-police-ignore tsConfig -->
|
|
299
|
-
|
|
300
|
-
```ts twoslash [nuxt.config.ts]
|
|
301
|
-
export default defineNuxtConfig({
|
|
302
|
-
typescript: {
|
|
303
|
-
tsConfig: {
|
|
304
|
-
compilerOptions: {
|
|
305
|
-
noUncheckedSideEffectImports: false,
|
|
306
|
-
},
|
|
307
|
-
},
|
|
308
|
-
},
|
|
96
|
+
On Nuxt 5 the same names are auto-imported from `nuxt/server`, so explicit imports written on Nuxt 4.6 keep working unchanged.
|
|
97
|
+
|
|
98
|
+
### Differences From h3 v1
|
|
99
|
+
|
|
100
|
+
| h3 v1 | `nuxt/server` |
|
|
101
|
+
|---|---|
|
|
102
|
+
| `sendRedirect(event, location)` sends the response. | `sendRedirect(event, location)` returns the response body: `return sendRedirect(event, '/login')`. |
|
|
103
|
+
| `getRouterParam(event, name)` and `getRouterParams(event)` return decoded values. | They return the values as they appear in the URL. Pass `{ decode: true }` to decode them. |
|
|
104
|
+
| `handleCors(event, options)` returns `true` when it answered a preflight request. | `handleCors(event, options)` returns the preflight `Response` to return from the handler, or `false`: `const preflight = handleCors(event, options); if (preflight) return preflight`. |
|
|
105
|
+
| `handleCors` accepts a single origin string at runtime. | `origin` is `'*'`, `'null'`, an array of origins or patterns, or a function: wrap a single origin in an array. `maxAge` is a string of seconds, such as `'86400'`, or `false`. Import the `CorsOptions` type from `nuxt/server`. |
|
|
106
|
+
| `readValidatedBody` and `getValidatedQuery` take a validation function. | They take a [Standard Schema](https://standardschema.dev) or a function. |
|
|
107
|
+
| `createError({ statusCode, statusMessage })` | `createError({ status, statusText })` |
|
|
108
|
+
| `isError(error)` | `isNuxtError(error)` |
|
|
109
|
+
| h3's `useSession`, `getSession`, `updateSession` and `clearSession` seal an `h3` cookie with the `password` you pass. | They seal a `nuxt-session` cookie, by default with a secret derived from `appSecret`. The two are not interchangeable: a session one issues does not unseal with the other. |
|
|
110
|
+
| `useRuntimeConfig(event)` | `useRuntimeConfig()`. There is no per-request form. |
|
|
111
|
+
| Global `$fetch` | Not part of `nuxt/server`. Call a route of the app with `serverFetch(event, path)`, which returns a `Response`. For other URLs, plain `fetch` does not throw on a non-2xx status and does not parse JSON: check `response.ok` and call `response.json()`. |
|
|
112
|
+
| `event.path` | `getRequestURL(event).pathname`, or `event.url.pathname`. |
|
|
113
|
+
| `event.node` | Not part of `nuxt/server`. Use `event.req` and `event.res`. |
|
|
114
|
+
| `getResponseHeader`, `setResponseHeader`, `appendResponseHeader`, `removeResponseHeader` | `event.res.headers.get()`, `.set()`, `.append()`, `.delete()` |
|
|
115
|
+
| `getMethod(event)`, `isMethod(event, method)`, `assertMethod(event, method)` | Compare `event.req.method`. |
|
|
116
|
+
| `readMultipartFormData(event)` | `await event.req.formData()` |
|
|
117
|
+
| `readRawBody(event)`, `getRequestWebStream(event)` | `await event.req.arrayBuffer()` (or `.text()`), `event.req.body` |
|
|
118
|
+
| `sanitizeStatusCode` | Not provided. |
|
|
119
|
+
|
|
120
|
+
### Helpers Outside `nuxt/server`
|
|
121
|
+
|
|
122
|
+
For a handler that needs h3 or Nitro helpers that `nuxt/server` does not provide, such as `readMultipartFormData`, `proxyRequest`, `useStorage` or `defineCachedEventHandler`, keep importing `defineEventHandler` and those helpers from `h3` (or `nitropack/runtime`) for that handler. Code that does this is tied to the server runtime and needs revisiting on Nuxt 5.
|
|
123
|
+
|
|
124
|
+
```ts [server/api/upload.post.ts]
|
|
125
|
+
import { defineEventHandler, readMultipartFormData } from 'h3'
|
|
126
|
+
|
|
127
|
+
export default defineEventHandler(async (event) => {
|
|
128
|
+
const parts = await readMultipartFormData(event)
|
|
129
|
+
return { received: parts?.length ?? 0 }
|
|
309
130
|
})
|
|
310
131
|
```
|
|
311
|
-
::
|
|
312
|
-
|
|
313
|
-
### Vue Options API Disabled by Default
|
|
314
|
-
|
|
315
|
-
🚦 **Impact Level**: Minimal
|
|
316
|
-
|
|
317
|
-
#### What Changed
|
|
318
|
-
|
|
319
|
-
With `compatibilityVersion: 5`, Nuxt sets Vue's [`__VUE_OPTIONS_API__`](https://vuejs.org/api/compile-time-flags#VUE_OPTIONS_API) feature flag to `false`, which compiles Vue's Options API runtime out of the client bundle.
|
|
320
|
-
|
|
321
|
-
#### Reasons for Change
|
|
322
132
|
|
|
323
|
-
|
|
133
|
+
### `NUXT_E8012`
|
|
324
134
|
|
|
325
|
-
|
|
135
|
+
A request fails with a `500` whose message starts with `[NUXT_E8012]` when a `nuxt/server` helper such as `readValidatedBody`, `getValidatedQuery`, `handleCors` or `useSession` receives an h3 event. This means the handler was defined with h3's `defineEventHandler` (usually the auto-imported one). Import `defineEventHandler` from `nuxt/server` in the same file as the helpers.
|
|
326
136
|
|
|
327
|
-
|
|
137
|
+
### Application Secret
|
|
328
138
|
|
|
329
|
-
|
|
330
|
-
export default defineNuxtConfig({
|
|
331
|
-
vue: {
|
|
332
|
-
optionsApi: true,
|
|
333
|
-
},
|
|
334
|
-
})
|
|
335
|
-
```
|
|
336
|
-
|
|
337
|
-
::note
|
|
338
|
-
`defineNuxtComponent` is unaffected: its `asyncData` and `head` options are handled through `setup()` rather than the Vue Options API, so it works regardless of this flag.
|
|
339
|
-
::
|
|
139
|
+
The `nuxt/server` session helpers and `deriveSecret` read `runtimeConfig.appSecret`, which you set with `NUXT_APP_SECRET`. On Nuxt 4, `nitropack` v2 parses environment overrides, so a secret made only of digits arrives as a number; see [the application secret](/docs/guide/going-further/runtime-config#application-secret) for how to avoid this.
|
|
340
140
|
|
|
341
141
|
## Migrating to Nuxt 4
|
|
342
142
|
|
|
@@ -432,7 +232,7 @@ Nuxt now defaults to a new directory structure, with backwards compatibility (so
|
|
|
432
232
|
- `layers/`, `modules/` and `public/` are resolved relative to `<rootDir>` by default
|
|
433
233
|
- if using [Nuxt Content v2.13+](https://github.com/nuxt/content/pull/2649), `content/` is resolved relative to `<rootDir>`
|
|
434
234
|
- a new `dir.app` is added, which is the directory we look for `router.options.ts` and `spa-loading-template.html` - this defaults to `<srcDir>/`
|
|
435
|
-
- a new [`shared/`](/docs/
|
|
235
|
+
- a new [`shared/`](/docs/directory-structure/shared) directory is available for code shared between the Vue app and the Nitro server, with auto-imports for `shared/utils/` and `shared/types/`
|
|
436
236
|
|
|
437
237
|
<details>
|
|
438
238
|
|
|
@@ -591,7 +391,7 @@ export default defineNuxtConfig({
|
|
|
591
391
|
|
|
592
392
|
#### What Changed
|
|
593
393
|
|
|
594
|
-
The order in which modules are loaded when using [Nuxt layers](/docs/
|
|
394
|
+
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.
|
|
595
395
|
|
|
596
396
|
Now modules are loaded in the correct order:
|
|
597
397
|
|
|
@@ -639,7 +439,7 @@ export default defineNuxtConfig({
|
|
|
639
439
|
// 4. project-module-2 (can override layer modules)
|
|
640
440
|
```
|
|
641
441
|
|
|
642
|
-
If you encounter issues with module order dependencies due to needing to register a hook, consider using the [`modules:done` hook](/docs/
|
|
442
|
+
If you encounter issues with module order dependencies due to needing to register a hook, consider using the [`modules:done` hook](/docs/guide/modules/recipes-advanced) 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.
|
|
643
443
|
|
|
644
444
|
👉 See [PR #31507](https://github.com/nuxt/nuxt/pull/31507) and [issue #25719](https://github.com/nuxt/nuxt/issues/25719) for more details.
|
|
645
445
|
|
|
@@ -1594,7 +1394,7 @@ In the table below, there is a quick comparison between 3 versions of Nuxt:
|
|
|
1594
1394
|
|
|
1595
1395
|
The migration guide provides a step-by-step comparison of Nuxt 2 features to Nuxt 3+ features and guidance to adapt your current application.
|
|
1596
1396
|
|
|
1597
|
-
::read-more{to="/docs/
|
|
1397
|
+
::read-more{to="/docs/migration/overview"}
|
|
1598
1398
|
Check out the **guide to migrating from Nuxt 2 to Nuxt 3**.
|
|
1599
1399
|
::
|
|
1600
1400
|
|
|
@@ -1602,6 +1402,6 @@ Check out the **guide to migrating from Nuxt 2 to Nuxt 3**.
|
|
|
1602
1402
|
|
|
1603
1403
|
If you prefer to progressively migrate your Nuxt 2 application to Nuxt 3, you can use Nuxt Bridge. Nuxt Bridge is a compatibility layer that allows you to use Nuxt 3+ features in Nuxt 2 with an opt-in mechanism.
|
|
1604
1404
|
|
|
1605
|
-
::read-more{to="/docs/
|
|
1405
|
+
::read-more{to="/docs/bridge/overview"}
|
|
1606
1406
|
**Migrate from Nuxt 2 to Nuxt Bridge**
|
|
1607
1407
|
::
|
|
@@ -6,7 +6,7 @@ navigation.icon: i-vscode-icons-folder-type-temp
|
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
::important
|
|
9
|
-
This directory should be added to your [`.gitignore`](/docs/
|
|
9
|
+
This directory should be added to your [`.gitignore`](/docs/directory-structure/gitignore) file to avoid pushing the dev build output to your repository.
|
|
10
10
|
::
|
|
11
11
|
|
|
12
12
|
This directory is interesting if you want to learn more about the files Nuxt generates based on your directory structure.
|
|
@@ -16,5 +16,5 @@ Nuxt also provides a Virtual File System (VFS) for modules to add templates to t
|
|
|
16
16
|
You can explore the generated files by opening the [Nuxt DevTools](https://devtools.nuxt.com) in development mode and navigating to the **Virtual Files** tab.
|
|
17
17
|
|
|
18
18
|
::warning
|
|
19
|
-
You should not touch any files inside since the whole directory will be re-created when running [`nuxt dev`](/docs/
|
|
19
|
+
You should not touch any files inside since the whole directory will be re-created when running [`nuxt dev`](/docs/api/commands/dev).
|
|
20
20
|
::
|
|
@@ -6,13 +6,13 @@ navigation.icon: i-vscode-icons-folder-type-package
|
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
::important
|
|
9
|
-
This directory should be added to your [`.gitignore`](/docs/
|
|
9
|
+
This directory should be added to your [`.gitignore`](/docs/directory-structure/gitignore) file to avoid pushing the build output to your repository.
|
|
10
10
|
::
|
|
11
11
|
|
|
12
12
|
Use this directory to deploy your Nuxt application to production.
|
|
13
13
|
|
|
14
|
-
:read-more{to="/docs/
|
|
14
|
+
:read-more{to="/docs/getting-started/deployment"}
|
|
15
15
|
|
|
16
16
|
::warning
|
|
17
|
-
You should not touch any files inside since the whole directory will be re-created when running [`nuxt build`](/docs/
|
|
17
|
+
You should not touch any files inside since the whole directory will be re-created when running [`nuxt build`](/docs/api/commands/build).
|
|
18
18
|
::
|
|
@@ -9,8 +9,8 @@ The directory usually contains the following types of files:
|
|
|
9
9
|
|
|
10
10
|
- Stylesheets (CSS, SASS, etc.)
|
|
11
11
|
- Fonts
|
|
12
|
-
- Images that won't be served from the [`public/`](/docs/
|
|
12
|
+
- Images that won't be served from the [`public/`](/docs/directory-structure/public) directory.
|
|
13
13
|
|
|
14
|
-
If you want to serve assets from the server, we recommend taking a look at the [`public/`](/docs/
|
|
14
|
+
If you want to serve assets from the server, we recommend taking a look at the [`public/`](/docs/directory-structure/public) directory.
|
|
15
15
|
|
|
16
|
-
:read-more{to="/docs/
|
|
16
|
+
:read-more{to="/docs/getting-started/assets"}
|