@nuxt/docs-nightly 5.0.0-2611190848-45e20ca → 5.0.0-2611191200-ecfdcc4

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.
@@ -1118,6 +1118,10 @@ See the rou3 migration guide for the other pattern syntax changes.
1118
1118
 
1119
1119
  Regex constraints in route rule patterns, such as `/products/:id([a-z0-9]+)`, are matched against the percent-encoded path. The build fails if a constraint can match `%` or a character that is percent-encoded in a path, such as `[é]`, a space, `.`, `\S` or a negated class like `[^a-z]`, or if it uses a word boundary (`\b` or `\B`). List the characters a constraint allows instead, or use a parameter without a constraint (such as `/products/:id`) to match any value.
1120
1120
 
1121
+ #### Route Rules: `headers` Apply After the Handler
1122
+
1123
+ Nitro v3 sets the headers of a `headers` route rule after the handler runs, so a rule header replaces a header of the same name that the handler sets, including one on a `Response` that the handler returns. This also applies to Nuxt 4 with Nitro v3, and the [Nitro v2 compatibility layer](#nitro-v2-compatibility) doesn't change it.
1124
+
1121
1125
  #### Server Storage Is Renamed to KV
1122
1126
 
1123
1127
  `useStorage()` from `nitro/storage` is now `useKV()` from `nitro/kv`, and the `nitro.storage` option is now `nitro.kv`. Mounts that only apply in development move from `nitro.devStorage` to `nitro.kv` under `$development`:
@@ -1820,6 +1824,8 @@ Two things follow from this:
1820
1824
  `ServerRoutes` from `@nuxt/schema` instead.
1821
1825
  - The `params` option is no longer accepted by `$fetch` or `useFetch`. It was an alias for `query`.
1822
1826
 
1827
+ A route written with `defineCachedHandler`, or with `defineCachedEventHandler` or `cachedEventHandler`, is typed by what the handler it caches returns. Called directly, a cached handler resolves to the `Response` it serves.
1828
+
1823
1829
  A path the generated route types do not describe still resolves, as `unknown`, unless you opt in to [`experimental.strictRouteTypes`](/docs/guide/going-further/experimental-features#strictroutetypes).
1824
1830
 
1825
1831
  #### Reasons for Change
@@ -1961,6 +1967,8 @@ export default defineNuxtConfig({
1961
1967
 
1962
1968
  With it on, `import { defineEventHandler, getQuery } from 'h3'`, `useRuntimeConfig(event)`, `defineNitroPlugin`, `cachedEventHandler`, `useEvent`, auto-imports from subdirectories of `server/utils/`, handlers registered without a `route`, and server files with a dotted suffix in their names, such as `server/middleware/auth.global.ts`, all keep working. A handler that returns a string still sends it as `text/html` unless it sets a content type, and a handler that returns `null` still responds with `204 No Content`, or with the status it set.
1963
1969
 
1970
+ The h3 v1 helpers that ended the response still end it. When a handler defined with `defineEventHandler` calls `sendRedirect`, `sendNoContent`, `send`, `sendStream`, `sendError`, `sendProxy` or `sendWebResponse`, or handles a preflight request with `handleCors`, Nuxt sends that response even if the handler returns nothing, and the request goes no further. A handler defined with `defineEventHandler({ handler, websocket })` still gets its `websocket` hooks for a WebSocket upgrade request.
1971
+
1964
1972
  With `nitroLegacy.h3` on, Nuxt also removes any server alias that points `h3` at h3 v1, such as one a module sets so that `h3` resolves to the copy `nitropack` depends on, and reports it with `NUXT_B9015`. Nitro v3 can't run h3 v1, so with the alias removed, Nitro v2 code gets the h3 v1 helpers and other server code gets h3 v2.
1965
1973
 
1966
1974
  Each part is a separate switch, so you can migrate one at a time:
@@ -1972,7 +1980,7 @@ export default defineNuxtConfig({
1972
1980
  specifiers: true, // `nitropack`, `nitropack/runtime`, `#internal/nitro`
1973
1981
  runtimeConfig: true, // the `useRuntimeConfig(event)` signature
1974
1982
  imports: false, // the Nitro v2 auto-import names, and nested `server/utils/` files
1975
- config: false, // Nitro v2 config shapes, dotted server file names, and removed-option warnings
1983
+ config: false, // Nitro v2 config shapes and dotted server file names
1976
1984
  },
1977
1985
  })
1978
1986
  ```
@@ -1981,11 +1989,14 @@ The `beforeResponse`, `afterResponse`, `render:before` and `render:response` hoo
1981
1989
 
1982
1990
  On Nuxt 4 with Nitro v3, when `nitroLegacy.config` is on, 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';`. On Nuxt 5, and on Nuxt 4 with `nitroLegacy.config` off, Nuxt doesn't add these headers to error responses.
1983
1991
 
1992
+ With `nitroLegacy.config` on, build hooks such as `prerender:done` can read and write the Nitro v2 build-time storage, `nitro.storage`. It has the `root:`, `src:`, `build:` (your `buildDir`), `cache:` and `data:` mounts, plus the ones you declare in `nitro.kv` and `nitro.devStorage`. The dev server and the prerenderer get the same `build:`, `cache:` and `data:` mounts, so what the prerenderer writes to `build:` can be read from `nitro.storage` once prerendering is done. Your production server doesn't get them. Unlike Nitro v2, cached handlers and functions keep the memory cache driver in development and while prerendering, unless you set `nitro.cache.driver` or declare a `cache` mount yourself.
1993
+
1984
1994
  ### What the Layer Doesn't Cover
1985
1995
 
1986
1996
  - **Undeclared dependencies.** `nitropack` v2 put its own dependencies into the server bundle, so a file could import something like `lru-cache` without depending on it and still work. Add the package to your own dependencies, or report it to the module that needs it.
1987
- - **Types.** If you augment `nitropack/types`, update it to the new module paths. See [Route Rule Types Move to `h3/rules`](#route-rule-types-move-to-h3rules). The layer changes how your server code runs, not how it type-checks. `useRuntimeConfig(event)` in a server route is still reported, because typed `$fetch` responses check route files alongside your app code, and an `H3Event` imported from a project dependency on h3 v1 does not match Nitro v3's event.
1988
- - **The event object.** With the default builder, `event` is h3 v2's event. The layer adds back some things h3 v2 dropped, such as `event.context.nitro`, `event.context._nitro.routeRules` and a Node-shaped `event.node` on runtimes that don't have one. Headers and the status you set on `event.node.res` apply to the response that Nitro sends.
1997
+ - **Types.** The layer mostly changes how your server code runs, not how it type-checks. With `nitroLegacy.specifiers`, an augmentation of `nitropack` or `nitropack/types`, in your code or a module's, applies to the Nitro v3 interface of the same name, such as `NitroRuntimeHooks`. Augmentations of `nitropack/runtime` and `#internal/nitro` are not picked up, and route rules are declared elsewhere (see [Route Rule Types Move to `h3/rules`](#route-rule-types-move-to-h3rules)). With `nitroLegacy.h3`, `h3` resolves to Nitro's 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 work when imported from `h3`, but they don't type-check that way. Their auto-imports are typed. `useRuntimeConfig(event)` in a server route is still reported, because typed `$fetch` responses check route files alongside your app code. For the same reason, an `H3Event` from `h3` in a server route is still reported by the app tsconfig, which resolves `h3` to your project's dependency.
1998
+ - **The event object.** With the default builder, `event` is h3 v2's event. The layer adds back some things h3 v2 dropped, such as `event.context.nitro`, `event.context._nitro.routeRules` and a Node-shaped `event.node` on runtimes that don't have one. Requests made in process, such as a server-side `$fetch` or `useFetch` to one of your own routes or a page being prerendered, get one too, with an `event.node.req.socket` whose `readyState` is `'readOnly'`, as in Nitro v2. Its `remoteAddress` is the client address of the request that made the call, or `undefined` when there is none. Headers and the status you set on `event.node.res` apply to the response that Nitro sends.
1999
+ - **The `close` hook while prerendering.** Nitro v3 stops the prerenderer without calling the runtime `close` hook, so a listener that saves data there never runs, and the data is lost. Nuxt names each Nitro v2 plugin that registers one with `NUXT_E8017`. Save the data as each route is prerendered instead, and read it back in a build hook.
1989
2000
 
1990
2001
  ### Migration Steps
1991
2002
 
@@ -79,7 +79,7 @@ export default defineNuxtPlugin({
79
79
  :video-accordion{title="Watch a video from Alexander Lichter about the Object Syntax for Nuxt plugins" videoId="2aXZyXB1QGQ"}
80
80
 
81
81
  ::note
82
- If you are using the object-syntax, `name`, `enforce`, `order`, `parallel` and `dependsOn` are statically analyzed at build time. Pass the object directly to `defineNuxtPlugin`, and use literal values (or top-level `const` variables in the same file that are initialized with one). Otherwise, Nuxt warns and resolves `name`, `dependsOn` and `parallel` at runtime instead, which produces a less optimized build. :br
82
+ If you are using the object-syntax, `name`, `enforce`, `order`, `parallel` and `dependsOn` are statically analyzed at build time. Pass the object directly to `defineNuxtPlugin`, and use literal values (or top-level `const` variables in the same file that are initialized with one). Otherwise, Nuxt warns and resolves `name`, `dependsOn` and `parallel` at runtime instead, which produces a less optimized build. Plugins installed in `node_modules` only produce this warning when [`debug`](/docs/api/nuxt-config#debug) is `true` or `debug.modules` is enabled. :br
83
83
  For example, setting `enforce: import.meta.server ? 'pre' : 'post'` would defeat any optimization Nuxt is able to do for your plugins.
84
84
  Nuxt does statically pre-load any hook listeners when using object-syntax, allowing you to define hooks without needing to worry about order of plugin registration.
85
85
  ::
@@ -983,6 +983,63 @@ Configuration for Nitro.
983
983
  }
984
984
  ```
985
985
 
986
+ ## nitroLegacy
987
+
988
+ Keep server code that you wrote for Nitro v2 and h3 v1 running on Nitro v3. The option applies to the `server/` and `shared/` directories of your project and its layers. Module server code written for Nitro v2 gets the compatibility layer whatever this option is set to.
989
+
990
+ Set it to `true` to turn on every switch below, or pass an object to choose them. A switch you leave out of the object is on.
991
+
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
+
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.
995
+
996
+ This option and the compatibility layer will be removed in Nuxt 6.
997
+
998
+ - **Type**: `boolean | object`
999
+ - **Default:** `false`
1000
+
1001
+ **See**: [Nitro v2 compatibility](/docs/getting-started/upgrade#nitro-v2-compatibility)
1002
+
1003
+ **Example**:
1004
+ ```ts
1005
+ export default defineNuxtConfig({
1006
+ nitroLegacy: {
1007
+ imports: false,
1008
+ config: false,
1009
+ },
1010
+ })
1011
+ ```
1012
+
1013
+ ### `config`
1014
+
1015
+ 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`.
1016
+
1017
+ - **Type**: `boolean`
1018
+
1019
+ ### `h3`
1020
+
1021
+ 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`.
1022
+
1023
+ - **Type**: `boolean`
1024
+
1025
+ ### `imports`
1026
+
1027
+ Auto-import the utilities that Nitro and h3 provide, including Nitro v2 names such as `defineNitroPlugin`, `cachedEventHandler` and `useEvent`, and the exports of files in subdirectories of `server/utils/`.
1028
+
1029
+ - **Type**: `boolean`
1030
+
1031
+ ### `runtimeConfig`
1032
+
1033
+ Accept `useRuntimeConfig(event)`, which returns a copy of the runtime config for that request.
1034
+
1035
+ - **Type**: `boolean`
1036
+
1037
+ ### `specifiers`
1038
+
1039
+ Resolve `nitropack`, `nitropack/runtime` and `#internal/nitro` to their Nitro v3 equivalents.
1040
+
1041
+ - **Type**: `boolean`
1042
+
986
1043
  ## optimization
987
1044
 
988
1045
  Build time optimization configuration.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/docs-nightly",
3
- "version": "5.0.0-2611190848-45e20ca",
3
+ "version": "5.0.0-2611191200-ecfdcc4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/nuxt.git",