@nuxt/docs-nightly 4.6.4-2611201708-0d5ff9b → 4.6.4-2611201909-8ffdfae

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.
@@ -117,7 +117,16 @@ Your app code doesn't change, and you don't need to change the [`server.builder`
117
117
 
118
118
  ### Nitro v2 Compatibility
119
119
 
120
- On Nuxt 4 with Nitro v3, the `nitroLegacy` option is enabled by default, so server code written for Nitro v2 keeps running. This covers imports from `h3`, `nitropack` and `#imports`, the Nitro v2 auto-imports, `useRuntimeConfig(event)`, `event.node`, and Nitro v2 hooks such as `render:response`. It also covers `h3` helpers that your app code imports and calls during server rendering, such as `getCookie(useRequestEvent()!, 'name')` in a component or composable.
120
+ On Nuxt 4 with Nitro v3, the `nitroLegacy` option is enabled by default, so server code written for Nitro v2 keeps running. This covers imports from `h3`, `nitropack` and `#imports`, the Nitro v2 auto-imports, `useRuntimeConfig(event)`, `event.node`, and the Nitro v2 hooks `render:before`, `render:response`, `beforeResponse` and `afterResponse`. It also covers `h3` helpers that your app code imports and calls during server rendering, such as `getCookie(useRequestEvent()!, 'name')` in a component or composable.
121
+
122
+ The layer also keeps these behaviors of Nitro v2 and h3 v1:
123
+
124
+ - **h3 v1 requests**: in a handler defined with `defineEventHandler`, the h3 v1 helpers that ended the response, such as `sendRedirect`, `send` or `handleCors` for a preflight request, still end it, and `defineEventHandler({ handler, websocket })` keeps its WebSocket hooks. The `onRequest` hooks of such a handler run for the requests it responds to, and not for its WebSocket upgrade request. The h3 v1 body readers, such as `readBody`, reject a `GET` request with `405`. Requests made in process, such as a server-side `useFetch` call to one of your own routes, get an `event.node.req.socket` whose `readyState` is `'readOnly'`. The [Nuxt 5 upgrade guide](https://nuxt.com/docs/5.x/getting-started/upgrade#your-own-server-directory) lists the helpers.
125
+ - **`render:before`**: a listener can respond in place of the page by setting `context.response`. A `Response` set as its `body` is sent as that response, and an `Error` is sent as an error response.
126
+ - **Server file names with a dotted suffix**: with `nitroLegacy.config`, a file such as `server/middleware/auth.global.ts` keeps working. Nuxt adds the suffix to `nitro.scanSuffixes` and lists the files with `NUXT_B9013`. With it off, `NUXT_B9014` lists the suffixes to add yourself, as described in [Server File Names Can't Contain Unknown Suffixes](https://nuxt.com/docs/5.x/getting-started/upgrade#server-file-names-cant-contain-unknown-suffixes).
127
+ - **Build-time storage**: with `nitroLegacy.config`, build hooks such as `prerender:done` can read and write `nitro.storage`, and the dev server and the prerenderer get its `build:`, `cache:` and `data:` mounts. The [Nuxt 5 upgrade guide](https://nuxt.com/docs/5.x/getting-started/upgrade#your-own-server-directory) describes the mounts.
128
+ - **Error response headers**: with `nitroLegacy.config`, error responses carry the `x-content-type-options: nosniff`, `x-frame-options: DENY` and `referrer-policy: no-referrer` headers, and JSON error responses also carry `content-security-policy: script-src 'none'; frame-ancestors 'none';`. With it off, Nuxt doesn't add these headers to error responses.
129
+ - **`redirect.statusCode` in route rules**: the route rule type accepts it, marked as deprecated, and Nuxt applies it as `redirect.status`. Keep `statusCode` while your project still builds with Nitro v2, which ignores `redirect.status`. With `nitroLegacy.config` off, the build lists these rules in a `NUXT_B7026` warning.
121
130
 
122
131
  The [Nitro v2 compatibility section](https://nuxt.com/docs/5.x/getting-started/upgrade#nitro-v2-compatibility) of the Nuxt 5 upgrade guide describes the layer and its individual switches. To find the server code that depends on it, turn it off:
123
132
 
@@ -135,16 +144,30 @@ If you set `experimental.nitroAutoImports: false` and don't set `nitroLegacy`, t
135
144
 
136
145
  The layer keeps Nitro v2 code resolving and running. It doesn't restore every behavior of Nitro v2 and h3 v1, so these differences remain:
137
146
 
147
+ - **`headers` route rules**: Nitro v3 applies a `headers` rule after the handler, so a rule header replaces a header of the same name that the handler sets, including one on a `Response` that the handler returns. `nitroLegacy` doesn't change this. See [Route Rules: `headers` Apply After the Handler](https://nuxt.com/docs/5.x/getting-started/upgrade#route-rules-headers-apply-after-the-handler).
138
148
  - **Server plugins**: `nitroApp.h3App` and `nitroApp.router` aren't available.
139
149
  - **The response on the event**: `event.res` is the h3 v2 response, with `event.res.headers` and `event.res.status`, rather than the Node.js response. `event.res.setHeader()` isn't available. Use `setResponseHeader(event, name, value)` or `event.node.res.setHeader()`.
140
150
  - **Runtime config environment variables**: values are [converted to the type of the value they replace](/docs/guide/going-further/runtime-config#environment-variables) rather than cast with `destr`, as with `future.compatibilityVersion: 5`.
141
151
  - **Runtime config per request**: environment variables are applied once, when the server starts, rather than again for each request. The object that `useRuntimeConfig()` returns without an event isn't frozen.
152
+ - **String responses**: a handler that returns a string sends it as `text/plain` unless it sets a content type. Handlers written for h3 v1, which the layer covers, still send `text/html`, as Nitro v2 did.
153
+ - **WebSocket upgrades**: server middleware runs for a WebSocket upgrade request, which Nitro v2 didn't do, but an error thrown there doesn't refuse the handshake. To refuse it, return or throw a `Response` from the `upgrade` hook of the WebSocket handler.
142
154
  - **JSON error responses**: the body carries `status` and `statusText`. While `nitroLegacy` is on, it also carries `statusCode` and `statusMessage`. It has no `url`. For an error thrown while rendering a page, the body includes the `message` of the error in production, where Nitro v2 sent `Server Error`.
143
- - **Cached routes**: responses are still cached per query string while `nitroLegacy.config` is on. With it off, [set `allowQuery`](https://nuxt.com/docs/5.x/getting-started/upgrade#cached-route-rules-ignore-query-parameters) to keep the query string.
155
+ - **`cache-control` of error responses**: error responses are sent with `cache-control: no-cache`. A `cache-control` set on the error itself is kept, and so is one that rules out reuse by a shared cache, such as `no-store` or `private`, whether it comes from a route rule or was set before the error. An error response that a handler returns, rather than throws, keeps the `cache-control` of its route rule.
156
+ - **Cached routes**: while `nitroLegacy.config` is on, responses are still cached per query string, and `cache` and `swr` route rules, `defineCachedEventHandler` and `cachedEventHandler` send the `cache-control` that Nitro v2 sent, such as `s-maxage=60, stale-while-revalidate` for `swr: 60` and `max-age=60` for `cache: { maxAge: 60 }`. A `cache-control` that the handler sets is replaced, unless it rules out shared caching, such as `private` or `no-store`. When the options set neither `maxAge` nor `swr`, `defineCachedEventHandler` and `cachedEventHandler` send the handler's own `cache-control`, or `public` if it sets none. A `cache` route rule without `maxAge` or `swr` sends `public`, also when the handler sets a value that a shared cache can reuse, such as `max-age=7`, where Nitro v2 sent the handler's value. It keeps a value that rules out shared caching. A response with a status that isn't cached, such as a `404` or `503` that the handler of `defineCachedEventHandler` returns, keeps the `cache-control` that the handler set, if any. A route rule that sets a `cache-control` header or the `sendCacheControl` option keeps its own value. With `nitroLegacy.config` off, Nitro v3 sends `public, max-age=60, s-maxage=60` for both examples, and you [set `allowQuery`](https://nuxt.com/docs/5.x/getting-started/upgrade#cached-route-rules-ignore-query-parameters) to keep the query string.
157
+ - **Types of cached handlers**: routes written with `defineCachedHandler`, `defineCachedEventHandler` or `cachedEventHandler` are typed by what the handler they cache returns. Called directly, a cached handler resolves to the `Response` it serves.
158
+ - **`cors` route rules**: a rule with `cors: true` responds to a CORS preflight request itself, so the `OPTIONS` request doesn't reach your handler. Nitro v2 only added the CORS headers.
159
+ - **`getRouteRules(event)`**: the result includes `ssr: true` for every path that Nuxt renders on the server, and leaves `ssr` out where a route rule sets it to `false`. Code that checks whether any rule matches a path, for example by counting the keys of the result, also counts `ssr`.
160
+ - **Request URL while prerendering**: the origin of a request that Nitro prerenders, as returned by [`useRequestURL()`](/docs/api/composables/use-request-url), is the address of the prerender worker, such as `http://127.0.0.1:41234`, and its port changes with every build. Nitro v2 used `http://localhost`. Build absolute URLs in prerendered pages, such as a canonical link, from a fixed value such as one in your runtime config. Relative `$fetch` and `useFetch` calls to your API routes and public assets aren't affected.
161
+ - **The `close` hook while prerendering**: a listener for the runtime `close` hook doesn't run when prerendering ends, and Nuxt names each Nitro v2 plugin that registers one with `NUXT_E8017`. The [Nuxt 5 upgrade guide](https://nuxt.com/docs/5.x/getting-started/upgrade#what-the-layer-doesnt-cover) describes how to save the data instead.
162
+ - **Dependencies in the server build**: Nitro v3 bundles the packages that your server code imports. If a package doesn't work once bundled, for example with an error when the server starts, list it in `nitro.traceDeps` to keep it out of the bundle and copy it into the build output.
163
+ - **Storage drivers**: a storage driver that needs a library, including one that a module mounts, needs that library in the dependencies of your project. When it's missing, Nitro v3 prompts you to install it, or installs it without asking in a non-interactive shell, and adds it to your `package.json`. In CI, and with `nitro: { deps: { install: false } }`, the build fails and names the package to add instead. `nitro.storage` and `nitro.devStorage` still work, with a deprecation warning. See [Server Storage Is Renamed to KV](https://nuxt.com/docs/5.x/getting-started/upgrade#server-storage-is-renamed-to-kv).
164
+ - **Modules**: some modules need a release that supports Nitro v3, such as `nuxt-security` 2.7.0 or later.
144
165
  - **Nitro configuration**: options that Nitro v3 removed are ignored, and the build lists them in a `NUXT_B9001` warning.
145
166
  - **Top-level `await` in server plugins**: `nuxt dev` doesn't start when the module of a server plugin uses a top-level `await`, because of a [bug in Rolldown](https://github.com/rolldown/rolldown/issues/9548), the bundler that Nitro v3 uses by default. Production builds aren't affected. Until the bug is fixed, run the dev server with the `NITRO_BUILDER=rollup` environment variable.
146
167
  - **Nitro as a Vite environment**: `experimental.nitroViteEnvironment` isn't supported on Nuxt 4. Nuxt turns it off, reports `NUXT_B5039`, and builds the server with Nitro's own bundler.
147
- - **Types**: your server code is type-checked against Nitro v3 and h3 v2. Move augmentations of `nitropack` or `nitropack/types` to `nitro/types`. An `H3Event` type imported from h3 v1 doesn't match the event your handlers receive. `$fetch` and `useFetch` responses are typed from the generated route types by default. Routes written with `defineCachedEventHandler` stay untyped.
168
+ - **Types**: your server code is type-checked against Nitro v3 and h3 v2. While `nitroLegacy.specifiers` is on, augmentations of `nitropack` and `nitropack/types` apply to the `nitro/types` interfaces of the same name. Augmentations of `nitropack/runtime` and `#internal/nitro` are not picked up, so move those to `nitro/types`. While `nitroLegacy.h3` is on, `h3` resolves to h3 v2 in the server tsconfig, even if your project depends on h3 v1, so an `H3Event` imported from `h3` matches the event your handlers receive. On that type, `event.node` is optional. Helpers that only h3 v1 has, such as `send`, `sendError` or `isStream`, still run when imported from `h3`, but they don't type-check that way. Their auto-imports are typed. `$fetch` and `useFetch` responses are typed from the generated route types by default. Those types check server routes alongside your app code, and the app tsconfig still resolves `h3` to your project's dependency, so it keeps reporting an `H3Event` from `h3` in a server route.
169
+ - **`$fetch` options**: `Parameters<typeof $fetch>[1]` isn't a type that `$fetch` accepts for a `string` URL, while it keeps working with Nitro v2 (`nitropack`). For a URL your app doesn't serve, type the options as `FetchOptions` from `nuxt/app` (or `#app` in app code), which is Nuxt's type. A file that already imports the `FetchOptions` type of `ofetch` needs to alias one of the two. Server code that calls ofetch's own `$fetch` should import `FetchOptions` from ofetch; Nuxt's `FetchOptions` is for Nuxt's typed `$fetch`. For a wrapper around your own routes with different defaults, use `$fetch.create`.
170
+ - **Replacing `globalThis.$fetch`**: with either Nitro version, `useFetch` and `useRequestFetch()` on the server are built from `globalThis.$fetch`. If you replace it, for example in a Nitro plugin, the replacement must be a complete `ofetch` instance, such as one created with `$fetch.create()`, and its defaults also apply to server-side `useFetch` requests.
148
171
 
149
172
  The remaining changes are listed under [Migration to Nitro v3](https://nuxt.com/docs/5.x/getting-started/upgrade#migration-to-nitro-v3) in the Nuxt 5 upgrade guide.
150
173
 
@@ -991,7 +991,7 @@ Set it to `true` to turn on every switch below, or pass an object to choose them
991
991
 
992
992
  While any switch is on, an error thrown with its own `statusCode`, such as `{ statusCode: 404, statusMessage: 'Not Found' }`, responds with that status instead of `500`. This applies to the whole app, and also happens when module server code gets the compatibility layer.
993
993
 
994
- In the same cases, Nuxt emits the Nitro v2 `beforeResponse`, `afterResponse`, `render:before` and `render:response` hooks. Nitro v2 plugins that the layer covers, and `useNitroApp()` imported from `nitropack/runtime`, get a `nitroApp.hooks.callHook()` that always returns a promise.
994
+ In the same cases, Nuxt emits the Nitro v2 `beforeResponse`, `afterResponse`, `render:before` and `render:response` hooks. Nitro v2 plugins that the layer covers, and `useNitroApp()` imported from `nitropack/runtime`, get a `nitroApp.hooks.callHook()` that always returns a promise, and JSON error responses carry `statusCode` and `statusMessage` alongside `status` and `statusText`.
995
995
 
996
996
  The option has no effect when Nuxt builds your server with Nitro v2 (`nitropack`). It's on by default when your project depends on `nitro`, so that Nuxt builds the server with Nitro v3, unless `future.compatibilityVersion` is `5`. If you set `experimental.nitroAutoImports: false` and leave `nitroLegacy` unset, the default is `{ imports: false }`, which keeps every other switch on.
997
997
 
@@ -1016,11 +1016,13 @@ export default defineNuxtConfig({
1016
1016
 
1017
1017
  Accept Nitro v2 config shapes: a server handler registered without a `route` runs as middleware for every request. Server files with a dotted suffix that Nitro v3 rejects, such as `server/middleware/auth.global.ts`, keep working: Nuxt adds the suffix to `nitro.scanSuffixes` and lists the files with `NUXT_B9013`.
1018
1018
 
1019
+ Cached handlers and cached routes keep the query string, because Nuxt sets `nitro.cache.defaults.allowQuery` to `true` unless you set it. `cache` and `swr` route rules, `defineCachedEventHandler` and `cachedEventHandler` send the `cache-control` of Nitro v2, such as `s-maxage=60, stale-while-revalidate` for `swr: 60`. A `cache` route rule that sets neither `maxAge` nor `swr` sends `public`, unless the handler sets a value that rules out shared caching. Error responses carry the `x-content-type-options: nosniff`, `x-frame-options: DENY` and `referrer-policy: no-referrer` headers, and JSON error responses also carry `content-security-policy: script-src 'none'; frame-ancestors 'none';`. A route rule that sets `redirect.statusCode` is applied as `redirect.status` without a `NUXT_B7026` warning.
1020
+
1019
1021
  - **Type**: `boolean`
1020
1022
 
1021
1023
  ### `h3`
1022
1024
 
1023
- Resolve `h3` and `h3/utils` imports in your server code to the h3 v1 helpers. Auto-imported h3 utilities resolve to them as well. Nuxt also removes server aliases that point `h3` at h3 v1, and lists them with `NUXT_B9015`.
1025
+ Resolve `h3` and `h3/utils` imports in your server code to the h3 v1 helpers. Auto-imported h3 utilities resolve to them as well, and so do `h3` imports in the server build of your app, such as a helper that a component calls during server rendering. Nuxt also removes server aliases that point `h3` at h3 v1, and lists them with `NUXT_B9015`.
1024
1026
 
1025
1027
  - **Type**: `boolean`
1026
1028
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/docs-nightly",
3
- "version": "4.6.4-2611201708-0d5ff9b",
3
+ "version": "4.6.4-2611201909-8ffdfae",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/nuxt.git",