Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion crates/next-error-code-swc-plugin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ fn is_error_class_name(name: &str) -> bool {
|| name == "DecodeError"
|| name == "DynamicServerError"
|| name == "ExportError"
|| name == "FatalError"
|| name == "ImageError"
|| name == "InstantValidationError"
|| name == "InvariantError"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,11 @@ export default function Counter() {

`"use client"` is used to declare a **boundary** between the Server and Client module graphs (trees).

Once a file is marked with `"use client"`, **all its imports and child components are considered part of the client bundle**. This means you don't need to add the directive to every component that is intended for the client.
Once a file is marked with `"use client"`, **all of its imports and the components it directly renders are included in the client bundle**. This means you don’t need to add the directive to every component that is intended for the client.

This behavior applies to components that are part of the Client Component’s [module graph](/docs/app/glossary#module-graph), which includes the modules it imports and the components it renders directly. It does not apply to Server Components passed as children or other props. Those components are not imported into the Client Component’s module graph. They are rendered on the server and passed to the Client Component as rendered output.

See [Interleaving Server and Client Components](/docs/app/getting-started/server-and-client-components#interleaving-server-and-client-components) for how Server and Client Components can be combined.

### Reducing JS bundle size

Expand Down Expand Up @@ -338,7 +342,7 @@ export default function Page() {
}
```

In this pattern, all Server Components will be rendered on the server ahead of time, including those as props. The resulting RSC payload will contain references of where Client Components should be rendered within the component tree.
In this pattern, Server Components are rendered on the server ahead of time, even when passed as props to Client Components. The React Server Component Payload contains the rendered result of those Server Components, plus placeholders for where Client Components should be rendered and references to their JavaScript files.

### Context providers

Expand Down
4 changes: 2 additions & 2 deletions docs/01-app/02-guides/authentication.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ const secretKey = process.env.SESSION_SECRET

#### 2. Encrypting and decrypting sessions

Next, you can use your preferred [session management library](#session-management-libraries) to encrypt and decrypt sessions. Continuing from the previous example, we'll use [Jose](https://www.npmjs.com/package/jose) (compatible with the [Edge Runtime](/docs/app/api-reference/edge)) and React's [`server-only`](https://www.npmjs.com/package/server-only) package to ensure that your session management logic is only executed on the server.
Next, you can use your preferred [session management library](#session-management-libraries) to encrypt and decrypt sessions. Continuing from the previous example, we'll use [Jose](https://www.npmjs.com/package/jose) and React's [`server-only`](https://www.npmjs.com/package/server-only) package to ensure that your session management logic is only executed on the server.

```tsx filename="app/lib/session.ts" switcher
import 'server-only'
Expand Down Expand Up @@ -1121,7 +1121,7 @@ While Proxy can be useful for initial checks, it should not be your only line of
> **Tips**:
>
> - In Proxy, you can also read cookies using `req.cookies.get('session').value`.
> - Proxy uses the Node.js runtime, check if your Auth library and session management library are compatible. You may need to use [Middleware](https://github.com/vercel/next.js/blob/v15.5.6/docs/01-app/03-api-reference/03-file-conventions/middleware.mdx) if your Auth library only supports [Edge Runtime](/docs/app/api-reference/edge)
> - Proxy uses the Node.js runtime, check if your Auth library and session management library are compatible.
> - You can use the `matcher` property in the Proxy to specify which routes Proxy should run on. Although, for auth, it's recommended Proxy runs on all routes.

<AppOnly>
Expand Down
2 changes: 1 addition & 1 deletion docs/01-app/02-guides/caching-without-cache-components.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export const revalidate = false
> **Good to know**:
>
> - The revalidate value needs to be statically analyzable. For example `revalidate = 600` is valid, but `revalidate = 60 * 10` is not.
> - The revalidate value is not available when using `runtime = 'edge'`.
> - The revalidate value is not available when using the deprecated `runtime = 'edge'`.
> - In Development, Pages are _always_ rendered on-demand and are never cached. This allows you to see changes immediately without waiting for a revalidation period to pass.

#### Revalidation frequency
Expand Down
2 changes: 1 addition & 1 deletion docs/01-app/02-guides/migrating-to-cache-components.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export default async function Page() {

## `runtime = 'edge'`

**Not supported.** Cache Components requires the Node.js runtime. Switch to the Node.js runtime (the default) by removing the `runtime = 'edge'` export. If you need edge behavior for specific routes, use [Proxy](/docs/app/api-reference/file-conventions/proxy) instead.
**Not supported.** Cache Components requires the Node.js runtime. Switch to the Node.js runtime (the default) by removing the [deprecated](/docs/messages/edge-runtime-deprecated) `runtime = 'edge'` export. If you need edge behavior for specific routes, use [Proxy](/docs/app/api-reference/file-conventions/proxy) instead.

## UI state preservation

Expand Down
2 changes: 0 additions & 2 deletions docs/01-app/02-guides/self-hosting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ Image Optimization can be used with a [static export](/docs/app/guides/static-ex

[Proxy](/docs/app/api-reference/file-conventions/proxy) works self-hosted with zero configuration when deploying using `next start`. Since it requires access to the incoming request, it is not supported when using a [static export](/docs/app/guides/static-exports).

Proxy uses the [Edge runtime](/docs/app/api-reference/edge), a subset of all available Node.js APIs to help ensure low latency, since it may run in front of every route or asset in your application. If you do not want this, you can use the [full Node.js runtime](/blog/next-15-2#nodejs-middleware-experimental) to run Proxy.

If you are looking to add logic (or use an external package) that requires all Node.js APIs, you might be able to move this logic to a [layout](/docs/app/api-reference/file-conventions/layout) as a [Server Component](/docs/app/getting-started/server-and-client-components). For example, checking [headers](/docs/app/api-reference/functions/headers) and [redirecting](/docs/app/api-reference/functions/redirect). You can also use headers, cookies, or query parameters to [redirect](/docs/app/api-reference/config/next-config-js/redirects#header-cookie-and-query-matching) or [rewrite](/docs/app/api-reference/config/next-config-js/rewrites#header-cookie-and-query-matching) through `next.config.js`. If that does not work, you can also use a [custom server](/docs/pages/guides/custom-server).

## Environment Variables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ description: Learn about how to configure options for Next.js route segments.

The Route Segment Config options allow you to configure the behavior of a [Page](/docs/app/api-reference/file-conventions/page), [Layout](/docs/app/api-reference/file-conventions/layout), or [Route Handler](/docs/app/api-reference/file-conventions/route) by directly exporting the following variables:

| Option | Type | Default |
| -------------------------------------------------------------------------------------------------- | ---------------------------------------------------- | -------------------------- |
| [`dynamicParams`](/docs/app/api-reference/file-conventions/route-segment-config/dynamicParams) | `boolean` | `true` |
| [`runtime`](/docs/app/api-reference/file-conventions/route-segment-config/runtime) | `'nodejs' \| 'edge'` | `'nodejs'` |
| [`preferredRegion`](/docs/app/api-reference/file-conventions/route-segment-config/preferredRegion) | `'auto' \| 'global' \| 'home' \| string \| string[]` | `'auto'` |
| [`maxDuration`](/docs/app/api-reference/file-conventions/route-segment-config/maxDuration) | `number` | Set by deployment platform |
| Option | Type | Default |
| -------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | -------------------------- |
| [`dynamicParams`](/docs/app/api-reference/file-conventions/route-segment-config/dynamicParams) | `boolean` | `true` |
| [`runtime`](/docs/app/api-reference/file-conventions/route-segment-config/runtime) | `'nodejs' \| 'edge' (deprecated)` | `'nodejs'` |
| [`preferredRegion`](/docs/app/api-reference/file-conventions/route-segment-config/preferredRegion) | `'auto' \| 'global' \| 'home' \| string \| string[] (deprecated)` | `'auto'` |
| [`maxDuration`](/docs/app/api-reference/file-conventions/route-segment-config/maxDuration) | `number` | Set by deployment platform |

## Version History

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
---
title: preferredRegion
title: preferredRegion (deprecated)
description: API reference for the preferredRegion route segment config option.
---

> **Deprecated:** The `preferredRegion` route segment config is deprecated. Remove the `preferredRegion` export from your route files. See the [deprecation message](/docs/messages/preferred-region-deprecated) for details.

The `preferredRegion` option allows you to specify the preferred deployment region for a route segment. This value is passed to your deployment platform.

```tsx filename="layout.tsx | page.tsx | route.ts" switcher
Expand All @@ -24,7 +26,7 @@ export const preferredRegion = // string || string[]

## Vercel

If deploying Next.js on Vercel, regions are only supported if `export const runtime = 'edge'` is set. The following options can be passed:
If deploying Next.js on Vercel, regions were previously only supported with `export const runtime = 'edge'`, which is now [deprecated](/docs/messages/edge-runtime-deprecated). The following options can be passed:

- **`'auto'`** (default): Uses the default region.
- **`'global'`**: Prefer deploying the route to all availableregions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ The `runtime` option allows you to select the JavaScript runtime used for render

```tsx filename="layout.tsx | page.tsx | route.ts" switcher
export const runtime = 'nodejs'
// 'nodejs' | 'edge'
// 'nodejs'
```

```js filename="layout.js | page.js | route.js" switcher
export const runtime = 'nodejs'
// 'nodejs' | 'edge'
// 'nodejs'
```

- **`'nodejs'`** (default)
- **`'edge'`**
- **`'edge'`** (deprecated)

> **Good to know**:
>
> - Using `runtime: 'edge'` is **not supported** for Cache Components.
> - The Edge Runtime is deprecated. Remove the `runtime` export from your route files. See [Edge Runtime Deprecated](/docs/messages/edge-runtime-deprecated).
> - This option cannot be used in [Proxy](/docs/app/api-reference/file-conventions/proxy).
4 changes: 2 additions & 2 deletions docs/01-app/03-api-reference/03-file-conventions/route.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ export const dynamicParams = true
export const revalidate = false
export const fetchCache = 'auto'
export const runtime = 'nodejs'
export const preferredRegion = 'auto'
export const preferredRegion = 'auto' // deprecated
```

```js filename="app/items/route.js" switcher
Expand All @@ -656,7 +656,7 @@ export const dynamicParams = true
export const revalidate = false
export const fetchCache = 'auto'
export const runtime = 'nodejs'
export const preferredRegion = 'auto'
export const preferredRegion = 'auto' // deprecated
```

See the [API reference](/docs/app/api-reference/file-conventions/route-segment-config) for more details.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ In addition, a number of built-in conditions are supported:
- `development`: Matches when using `next dev`.
- `production`: Matches when using `next build`.
- `node`: Matches code that will run on the default Node.js runtime.
- `edge-light`: Matches code that will run on the [Edge runtime](/docs/app/api-reference/edge).
- `edge-light`: Matches code that will run on the [Edge runtime](/docs/app/api-reference/edge) (deprecated).

Rules can be an object or an array of objects. An array is often useful for modeling disjoint conditions:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ Relevant files in the Next.js core:
- [`packages/next/src/build/templates/app-route.ts`](https://github.com/vercel/next.js/blob/canary/packages/next/src/build/templates/app-route.ts)
- and [`packages/next/src/build/templates/pages-api.ts`](https://github.com/vercel/next.js/blob/canary/packages/next/src/build/templates/pages-api.ts)

## Edge runtime (`runtime: 'edge'`)
## Edge runtime (`runtime: 'edge'`) (deprecated)

> The Edge Runtime is [deprecated](/docs/messages/edge-runtime-deprecated). New routes should use the Node.js runtime.

Edge entrypoints use the following interface:

Expand Down
12 changes: 6 additions & 6 deletions docs/01-app/03-api-reference/07-adapters/09-output-types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The `outputs` object contains arrays of build output types:

> **Note:** When `config.output` is set to `'export'`, only `outputs.staticFiles` is populated. All other arrays (`pages`, `appPages`, `pagesApi`, `appRoutes`, `prerenders`) will be empty since the entire application is exported as static files.

For any route output with `runtime: 'edge'`, `edgeRuntime` is included and contains the canonical entry metadata for invoking that output in your edge runtime.
For any route output with `runtime: 'edge'`, `edgeRuntime` is included and contains the canonical entry metadata for invoking that output in your edge runtime. Note that the Edge Runtime is [deprecated](/docs/messages/edge-runtime-deprecated).

## Pages (`outputs.pages`)

Expand All @@ -38,7 +38,7 @@ React pages from the `pages/` directory:
}
config: {
maxDuration?: number // Maximum duration of the route in seconds
preferredRegion?: string | string[] // Preferred deployment region
preferredRegion?: string | string[] // Preferred deployment region (deprecated)
env?: Record<string, string> // Environment variables (edge runtime only)
}
}
Expand All @@ -65,7 +65,7 @@ API routes from `pages/api/`:
}
config: {
maxDuration?: number // Maximum duration of the route in seconds
preferredRegion?: string | string[] // Preferred deployment region
preferredRegion?: string | string[] // Preferred deployment region (deprecated)
env?: Record<string, string> // Environment variables (edge runtime only)
}
}
Expand All @@ -92,7 +92,7 @@ React pages from the `app/` directory:
}
config: {
maxDuration?: number // Maximum duration of the route in seconds
preferredRegion?: string | string[] // Preferred deployment region
preferredRegion?: string | string[] // Preferred deployment region (deprecated)
env?: Record<string, string> // Environment variables (edge runtime only)
}
}
Expand All @@ -119,7 +119,7 @@ API and metadata routes from the `app/` directory:
}
config: {
maxDuration?: number // Maximum duration of the route in seconds
preferredRegion?: string | string[] // Preferred deployment region
preferredRegion?: string | string[] // Preferred deployment region (deprecated)
env?: Record<string, string> // Environment variables (edge runtime only)
}
}
Expand Down Expand Up @@ -194,7 +194,7 @@ Static assets and auto-statically optimized pages:
}
config: {
maxDuration?: number // Maximum duration of the route in seconds
preferredRegion?: string | string[] // Preferred deployment region
preferredRegion?: string | string[] // Preferred deployment region (deprecated)
env?: Record<string, string> // Environment variables (edge runtime only)
matchers?: Array<{
source: string // Source pattern
Expand Down
23 changes: 23 additions & 0 deletions errors/edge-runtime-deprecated.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
title: Edge Runtime Deprecated
---

## Why This Warning Occurred

One or more routes in your application use `export const runtime = 'edge'`, which is deprecated.

## How to Migrate

Remove the `runtime` export from your route files:

```diff
- export const runtime = 'edge'
```

The Node.js runtime is the default, so no replacement is needed.

This applies to all route files that support the `runtime` segment config: `page.ts`, `layout.ts`, `route.ts`, and API routes.

## Useful Links

- [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config/runtime)
21 changes: 21 additions & 0 deletions errors/preferred-region-deprecated.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
title: preferredRegion Deprecated
---

## Why This Warning Occurred

One or more routes in your application use `export const preferredRegion`, which is deprecated.

## How to Migrate

Remove the `preferredRegion` export from your route files:

```diff
- export const preferredRegion = 'home'
```

This applies to all route files that support the `preferredRegion` segment config: `page.ts`, `layout.ts`, and `route.ts`.

## Useful Links

- [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config/preferredRegion)
20 changes: 20 additions & 0 deletions packages/next/src/build/analysis/get-page-static-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import {
import { tryToParsePath } from '../../lib/try-to-parse-path'
import { isAPIRoute } from '../../lib/is-api-route'
import { isEdgeRuntime } from '../../lib/is-edge-runtime'
import {
warnAboutEdgeRuntime,
warnAboutPreferredRegion,
} from '../warn-about-edge-runtime'
import { RSC_MODULE_TYPES } from '../../shared/lib/constants'
import type { RSCMeta } from '../webpack/loaders/get-module-build-info'
import { PAGE_TYPES } from '../../lib/page-types'
Expand Down Expand Up @@ -721,6 +725,14 @@ export async function getAppPageStaticInfo({
)
}

if (isEdgeRuntime(config.runtime)) {
warnAboutEdgeRuntime()
}

if (config.preferredRegion !== undefined) {
warnAboutPreferredRegion()
}

return {
type: PAGE_TYPES.APP,
rsc,
Expand Down Expand Up @@ -831,6 +843,14 @@ export async function getPagesPageStaticInfo({
}
}

if (isEdgeRuntime(resolvedRuntime)) {
warnAboutEdgeRuntime()
}

if (config.config?.regions !== undefined) {
warnAboutPreferredRegion()
}

return {
type: PAGE_TYPES.PAGES,
getStaticProps,
Expand Down
19 changes: 19 additions & 0 deletions packages/next/src/build/warn-about-edge-runtime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as Log from './output/log'

export function warnAboutEdgeRuntime() {
// Webpack build workers each run in a separate process with their own
// warnOnce cache, so the same warning would be emitted once per worker.
// Suppress in workers; the main build process emits the warning once during
// the "Collecting page data" phase.
if (process.env.NEXT_PRIVATE_BUILD_WORKER) return
Log.warnOnce(
`The Edge Runtime is deprecated. You can use the "nodejs" runtime instead. Learn more: https://nextjs.org/docs/messages/edge-runtime-deprecated`
)
}

export function warnAboutPreferredRegion() {
if (process.env.NEXT_PRIVATE_BUILD_WORKER) return
Log.warnOnce(
`The "preferredRegion" route segment config is deprecated. Learn more: https://nextjs.org/docs/messages/preferred-region-deprecated`
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ checkFields<Diff<{
dynamic?: 'auto' | 'force-dynamic' | 'error' | 'force-static'
dynamicParams?: boolean
fetchCache?: 'auto' | 'force-no-store' | 'only-no-store' | 'default-no-store' | 'default-cache' | 'only-cache' | 'force-cache'
/** @deprecated The \`preferredRegion\` config is deprecated. Remove this export. */
preferredRegion?: 'auto' | 'global' | 'home' | string | string[]
runtime?: 'nodejs' | 'experimental-edge' | 'edge'
maxDuration?: number
Expand Down
1 change: 0 additions & 1 deletion packages/next/src/lib/fatal-error.ts

This file was deleted.

Loading
Loading