mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
84f1e44d4d
Note: re-apply of #92817 ### What? Deprecates the Edge Runtime and the `preferredRegion` route segment config that only applied to edge runtime with build-time warnings, TypeScript IDE hints, error documentation pages, and documentation updates. ### Why? Edge Runtime in Next.js is being deprecated in favor of the Node.js runtime (the default). The `preferredRegion` route segment config is tightly coupled to Edge Runtime and is also being deprecated. ### How? **Edge Runtime deprecation:** - Added `warnAboutEdgeRuntime()` helper using `Log.warnOnce` in `packages/next/src/build/warn-about-edge-runtime.ts` - Warning fires in `get-page-static-info.ts` (Webpack dev/build + Turbopack build) and `turbopack-utils.ts` (Turbopack dev) when `runtime = 'edge'` is detected - Marked `'edge'` as `@deprecated` in the TypeScript language service plugin (`rules/config.ts`) - Created `errors/edge-runtime-deprecated.mdx` with migration guidance - Updated documentation across 11 files to add deprecation notices or simplify/remove outdated Edge Runtime references **`preferredRegion` deprecation:** - Added `warnAboutPreferredRegion()` helper in the same file - Warning fires in `get-page-static-info.ts` for both App Router (`config.preferredRegion`) and Pages Router (`config.config?.regions`) - Marked `preferredRegion` as `@deprecated` in the TypeScript language service plugin and the generated types (`next-types-plugin`) - Created `errors/preferred-region-deprecated.mdx` with migration guidance (remove the export) - Updated documentation across 4 files to add deprecation notices **Tests:** - Added `test/e2e/edge-runtime-deprecated/` with fixture and assertions for the edge runtime warning (dev + production) - Added `test/production/preferred-region-deprecated/` with fixture and assertions for the preferredRegion warning (production only -- Turbopack dev does not surface `preferredRegion` from the Rust layer to JS) <!-- NEXT_JS_LLM_PR --> --------- Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
38 lines
1.0 KiB
TypeScript
38 lines
1.0 KiB
TypeScript
import { nextTestSetup } from 'e2e-utils'
|
|
import { retry } from 'next-test-utils'
|
|
|
|
const EXPECTED_WARNING =
|
|
'The Edge Runtime is deprecated. You can use the "nodejs" runtime instead.'
|
|
|
|
describe('edge-runtime-deprecated', () => {
|
|
const { next, isNextDev } = nextTestSetup({
|
|
files: __dirname,
|
|
})
|
|
|
|
it('should warn about deprecated edge runtime', async () => {
|
|
if (isNextDev) {
|
|
// In dev mode, the warning fires when the edge route is first compiled.
|
|
await next.fetch('/edge-route')
|
|
}
|
|
|
|
await retry(async () => {
|
|
expect(next.cliOutput).toContain(EXPECTED_WARNING)
|
|
})
|
|
})
|
|
|
|
it('should only warn once', async () => {
|
|
if (isNextDev) {
|
|
// Trigger compilation of the edge route again (already compiled, but
|
|
// another request ensures no duplicate warnings).
|
|
await next.fetch('/edge-route')
|
|
}
|
|
|
|
await retry(async () => {
|
|
expect(next.cliOutput).toContain(EXPECTED_WARNING)
|
|
})
|
|
|
|
const occurrences = next.cliOutput.split(EXPECTED_WARNING).length - 1
|
|
expect(occurrences).toBe(1)
|
|
})
|
|
})
|