Commit cd27516c authored by Tim Neutkens's avatar Tim Neutkens

Deprecate preferredRegion as it's linked to edge runtime

parent a094eab7
......@@ -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' (deprecated)` | `'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
......
---
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
......
......@@ -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
......@@ -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.
......
......@@ -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)
}
}
......@@ -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)
}
}
......@@ -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)
}
}
......@@ -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)
}
}
......@@ -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
......
---
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)
......@@ -15,7 +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 } from '../warn-about-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'
......@@ -726,6 +729,10 @@ export async function getAppPageStaticInfo({
warnAboutEdgeRuntime()
}
if (config.preferredRegion !== undefined) {
warnAboutPreferredRegion()
}
return {
type: PAGE_TYPES.APP,
rsc,
......@@ -840,6 +847,10 @@ export async function getPagesPageStaticInfo({
warnAboutEdgeRuntime()
}
if (config.config?.regions !== undefined) {
warnAboutPreferredRegion()
}
return {
type: PAGE_TYPES.PAGES,
getStaticProps,
......
......@@ -5,3 +5,9 @@ export function warnAboutEdgeRuntime() {
`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() {
Log.warnOnce(
`The "preferredRegion" route segment config is deprecated. Learn more: https://nextjs.org/docs/messages/preferred-region-deprecated`
)
}
......@@ -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
......
......@@ -61,12 +61,12 @@ const API_DOCS: Record<
},
preferredRegion: {
description:
'Specify the perferred region that this layout or page should be deployed to. If the region option is not specified, it inherits the option from the nearest parent layout. The root defaults to `"auto"`.\n\nYou can also specify a region, such as "iad1", or an array of regions, such as `["iad1", "sfo1"]`.',
'@deprecated\\n\\nThe `preferredRegion` route segment config is deprecated. Remove this export.',
options: {
'"auto"':
'Next.js will first deploy to the `"home"` region. Then if it doesn\'t detect any waterfall requests after a few requests, it can upgrade that route, to be deployed globally. If it detects any waterfall requests after that, it can eventually downgrade back to `"home`".',
'"global"': 'Prefer deploying globally.',
'"home"': 'Prefer deploying to the Home region.',
'@deprecated\\n\\nNext.js will first deploy to the `"home"` region. Then if it doesn\'t detect any waterfall requests after a few requests, it can upgrade that route, to be deployed globally. If it detects any waterfall requests after that, it can eventually downgrade back to `"home`".',
'"global"': '@deprecated\\n\\nPrefer deploying globally.',
'"home"': '@deprecated\\n\\nPrefer deploying to the Home region.',
},
link: 'https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#preferredregion',
isValid: (value: string) => {
......
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
export default function Page() {
return <p>Hello</p>
}
export const preferredRegion = 'home'
export function GET() {
return new Response('region route')
}
import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'
const EXPECTED_WARNING =
'The "preferredRegion" route segment config is deprecated.'
describe('preferred-region-deprecated', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('should warn about deprecated preferredRegion', async () => {
await retry(async () => {
expect(next.cliOutput).toContain(EXPECTED_WARNING)
})
})
it('should only warn once', async () => {
await retry(async () => {
expect(next.cliOutput).toContain(EXPECTED_WARNING)
})
const occurrences = next.cliOutput.split(EXPECTED_WARNING).length - 1
expect(occurrences).toBe(1)
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment