Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename page runtime edge to experimental-edge #38041

Merged
merged 7 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion docs/advanced-features/react-18/server-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = {
}
```

Using `runtime` also enables [Streaming SSR](/docs/advanced-features/react-18/streaming). When setting `runtime` to `'edge'`, the server will be running entirely in the [Edge Runtime](https://nextjs.org/docs/api-reference/edge-runtime).
Using `runtime` also enables [Streaming SSR](/docs/advanced-features/react-18/streaming). When setting `runtime` to `'experimental-edge'`, the server will be running entirely in the [Edge Runtime](https://nextjs.org/docs/api-reference/edge-runtime).

Now, you can start using React Server Components in Next.js. [See our example](https://github.com/vercel/next-rsc-demo) for more information.

Expand Down
4 changes: 2 additions & 2 deletions docs/advanced-features/react-18/switchable-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ If you have [React 18](/docs/advanced-features/react-18/overview) installed, the

## Global Runtime Option

You can set the experimental option `runtime` to either `'nodejs'` or `'edge'` in your `next.config.js` file:
You can set the experimental option `runtime` to either `'nodejs'` or `'experimental-edge'` in your `next.config.js` file:

```jsx
// next.config.js
Expand All @@ -23,7 +23,7 @@ This option determines which runtime should be used as the default rendering run

## Page Runtime Option

On each page, you can optionally export a `runtime` config set to either `'nodejs'` or `'edge'`:
On each page, you can optionally export a `runtime` config set to either `'nodejs'` or `'experimental-edge'`:

```jsx
export const config = {
Expand Down
2 changes: 1 addition & 1 deletion packages/next/build/analysis/extract-const-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type {

/**
* Extracts the value of an exported const variable named `exportedName`
* (e.g. "export const config = { runtime: 'edge' }") from swc's AST.
* (e.g. "export const config = { runtime: 'experimental-edge' }") from swc's AST.
* The value must be one of (or throws UnsupportedValueError):
* - string
* - boolean
Expand Down
15 changes: 8 additions & 7 deletions packages/next/build/analysis/get-page-static-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { parseModule } from './parse-module'
import { promises as fs } from 'fs'
import { tryToParsePath } from '../../lib/try-to-parse-path'
import * as Log from '../output/log'
import { PAGE_RUNTIME } from '../../lib/constants'

interface MiddlewareConfig {
pathMatcher: RegExp
Expand Down Expand Up @@ -39,15 +40,15 @@ export async function getPageStaticInfo(params: {
const { ssg, ssr } = checkExports(swcAST)
const config = tryToExtractExportedConstValue(swcAST, 'config') || {}

let runtime = ['experimental-edge', 'edge'].includes(config?.runtime)
? 'edge'
: ssr || ssg
? config?.runtime || nextConfig.experimental?.runtime
: undefined
let runtime =
PAGE_RUNTIME.edge === config?.runtime
? PAGE_RUNTIME.edge
: ssr || ssg
? config?.runtime || nextConfig.experimental?.runtime
: undefined

if (runtime === 'experimental-edge' || runtime === 'edge') {
if (runtime === PAGE_RUNTIME.edge) {
warnAboutExperimentalEdgeApiFunctions()
runtime = 'edge'
}

const middlewareConfig = getMiddlewareConfig(config, nextConfig)
Expand Down
5 changes: 3 additions & 2 deletions packages/next/build/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
PAGES_DIR_ALIAS,
ROOT_DIR_ALIAS,
APP_DIR_ALIAS,
PAGE_RUNTIME,
} from '../lib/constants'
import {
CLIENT_STATIC_FILES_RUNTIME_AMP,
Expand Down Expand Up @@ -444,7 +445,7 @@ export function runDependingOnPageType<T>(params: {
if (isMiddlewareFile(params.page)) {
return { edgeServer: params.onEdgeServer() }
} else if (params.page.match(API_ROUTE)) {
return params.pageRuntime === 'edge'
return params.pageRuntime === PAGE_RUNTIME.edge
? { edgeServer: params.onEdgeServer() }
: { server: params.onServer() }
} else if (params.page === '/_document') {
Expand All @@ -457,7 +458,7 @@ export function runDependingOnPageType<T>(params: {
) {
return { client: params.onClient(), server: params.onServer() }
} else {
return params.pageRuntime === 'edge'
return params.pageRuntime === PAGE_RUNTIME.edge
? { client: params.onClient(), edgeServer: params.onEdgeServer() }
: { client: params.onClient(), server: params.onServer() }
}
Expand Down
3 changes: 2 additions & 1 deletion packages/next/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
PUBLIC_DIR_MIDDLEWARE_CONFLICT,
MIDDLEWARE_FILENAME,
PAGES_DIR_ALIAS,
PAGE_RUNTIME,
} from '../lib/constants'
import { fileExists } from '../lib/file-exists'
import { findPagesDir } from '../lib/find-pages-dir'
Expand Down Expand Up @@ -1117,7 +1118,7 @@ export default async function build(
if (
!isReservedPage(page) &&
// We currently don't support static optimization in the Edge runtime.
pageRuntime !== 'edge'
pageRuntime !== PAGE_RUNTIME.edge
) {
try {
let isPageStaticSpan =
Expand Down
5 changes: 3 additions & 2 deletions packages/next/build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
SERVER_PROPS_GET_INIT_PROPS_CONFLICT,
SERVER_PROPS_SSG_CONFLICT,
MIDDLEWARE_FILENAME,
PAGE_RUNTIME,
} from '../lib/constants'
import { EDGE_RUNTIME_WEBPACK } from '../shared/lib/constants'
import prettyBytes from '../lib/pretty-bytes'
Expand Down Expand Up @@ -194,7 +195,7 @@ export async function printTreeView(
? '○'
: pageInfo?.isSsg
? '●'
: pageInfo?.runtime === 'edge'
: pageInfo?.runtime === PAGE_RUNTIME.edge
? 'ℇ'
: 'λ'

Expand Down Expand Up @@ -1301,7 +1302,7 @@ export async function isEdgeRuntimeCompiled(

// Check the page runtime as well since we cannot detect the runtime from
// compilation when it's for the client part of edge function
return staticInfo.runtime === 'edge'
return staticInfo.runtime === PAGE_RUNTIME.edge
}

export function getNodeBuiltinModuleNotSupportedInEdgeRuntimeMessage(
Expand Down
3 changes: 2 additions & 1 deletion packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
PAGES_DIR_ALIAS,
ROOT_DIR_ALIAS,
APP_DIR_ALIAS,
PAGE_RUNTIME,
} from '../lib/constants'
import { fileExists } from '../lib/file-exists'
import { CustomRoutes } from '../lib/load-custom-routes.js'
Expand Down Expand Up @@ -385,7 +386,7 @@ export default async function getBaseWebpackConfig(
: config.experimental.disableOptimizedLoading

if (isClient) {
if (config.experimental.runtime === 'edge') {
if (config.experimental.runtime === PAGE_RUNTIME.edge) {
Log.warn(
'You are using the experimental Edge Runtime with `experimental.runtime`.'
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
WebNextRequest,
WebNextResponse,
} from '../../../../server/base-http/web'
import { PAGE_RUNTIME } from '../../../../lib/constants'

export function getRender({
dev,
Expand Down Expand Up @@ -55,7 +56,7 @@ export function getRender({
page,
extendRenderOpts: {
buildId,
runtime: 'edge',
runtime: PAGE_RUNTIME.edge,
supportsDynamicHTML: true,
disableOptimizedLoading: true,
serverComponentManifest,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { PAGE_RUNTIME } from '../../../lib/constants'

export default async function transformSource(this: any): Promise<string> {
let { modules, runtime, ssr } = this.getOptions()
if (!Array.isArray(modules)) {
Expand All @@ -18,7 +20,7 @@ export default async function transformSource(this: any): Promise<string> {
export default function RSC() {};
` +
// Currently for the Edge runtime, we treat all RSC pages as SSR pages.
(runtime === 'edge'
(runtime === PAGE_RUNTIME.edge
? 'export const __N_SSP = true;'
: ssr
? `export const __N_SSP = true;`
Expand Down
3 changes: 2 additions & 1 deletion packages/next/build/webpack/plugins/client-entry-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
entries,
} from '../../../server/dev/on-demand-entry-handler'
import { getPageStaticInfo } from '../../analysis/get-page-static-info'
import { PAGE_RUNTIME } from '../../../lib/constants'

type Options = {
dev: boolean
Expand Down Expand Up @@ -111,7 +112,7 @@ export class ClientEntryPlugin {

const clientLoader = `next-flight-client-entry-loader?${stringify({
modules: clientComponentImports,
runtime: this.isEdgeServer ? 'edge' : 'nodejs',
runtime: this.isEdgeServer ? PAGE_RUNTIME.edge : PAGE_RUNTIME.nodejs,
ssr: pageStaticInfo.ssr,
// Adding name here to make the entry key unique.
name,
Expand Down
6 changes: 6 additions & 0 deletions packages/next/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { PageRuntime } from '../server/config-shared'
import { join } from '../shared/lib/isomorphic/path'

export const NEXT_PROJECT_ROOT = join(__dirname, '..', '..')
Expand Down Expand Up @@ -84,3 +85,8 @@ export const ESLINT_PROMPT_VALUES = [
config: null,
},
]

export const PAGE_RUNTIME: Record<string, PageRuntime> = {
edge: 'experimental-edge',
nodejs: 'nodejs',
}
3 changes: 2 additions & 1 deletion packages/next/server/app-render.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { IncomingMessage, ServerResponse } from 'http'
import type { LoadComponentsReturnType } from './load-components'
import type { PageRuntime } from './config-shared'

import React from 'react'
import { ParsedUrlQuery, stringify as stringifyQuery } from 'querystring'
Expand Down Expand Up @@ -30,7 +31,7 @@ export type RenderOptsPartial = {
dev?: boolean
serverComponentManifest?: any
supportsDynamicHTML?: boolean
runtime?: 'nodejs' | 'edge'
runtime?: PageRuntime
serverComponents?: boolean
}

Expand Down
8 changes: 6 additions & 2 deletions packages/next/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import type { FontManifest } from './font-utils'
import type { LoadComponentsReturnType } from './load-components'
import type { RouteMatch } from '../shared/lib/router/utils/route-matcher'
import type { Params } from '../shared/lib/router/utils/route-matcher'
import type { NextConfig, NextConfigComplete } from './config-shared'
import type {
NextConfig,
NextConfigComplete,
PageRuntime,
} from './config-shared'
import type { NextParsedUrlQuery, NextUrlWithParsedQuery } from './request-meta'
import type { ParsedUrlQuery } from 'querystring'
import type { RenderOpts, RenderOptsPartial } from './render'
Expand Down Expand Up @@ -172,7 +176,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
defaultLocale?: string
domainLocales?: DomainLocale[]
distDir: string
runtime?: 'nodejs' | 'edge'
runtime?: PageRuntime
serverComponents?: boolean
crossOrigin?: string
supportsDynamicHTML?: boolean
Expand Down
2 changes: 1 addition & 1 deletion packages/next/server/config-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
RemotePattern,
} from '../shared/lib/image-config'

export type PageRuntime = 'nodejs' | 'edge' | undefined
export type PageRuntime = 'nodejs' | 'experimental-edge' | undefined

export type NextConfigComplete = Required<NextConfig> & {
images: Required<ImageConfigComplete>
Expand Down
3 changes: 2 additions & 1 deletion packages/next/server/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import type { LoadComponentsReturnType, ManifestItem } from './load-components'
import type { GetServerSideProps, GetStaticProps, PreviewData } from '../types'
import type { UnwrapPromise } from '../lib/coalesced-function'
import type { ReactReadableStream } from './node-web-streams-helper'
import type { PageRuntime } from './config-shared'

import React from 'react'
import { createFromReadableStream } from 'next/dist/compiled/react-server-dom-webpack'
Expand Down Expand Up @@ -238,7 +239,7 @@ export type RenderOptsPartial = {
domainLocales?: DomainLocale[]
disableOptimizedLoading?: boolean
supportsDynamicHTML?: boolean
runtime?: 'nodejs' | 'edge'
runtime?: PageRuntime
serverComponents?: boolean
customServer?: boolean
crossOrigin?: string
Expand Down
2 changes: 1 addition & 1 deletion packages/next/server/web-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export default class NextWebServer extends BaseServer<WebServerOptions> {
{
...renderOpts,
disableOptimizedLoading: true,
runtime: 'edge',
runtime: 'experimental-edge',
}
)
}
Expand Down
3 changes: 2 additions & 1 deletion packages/next/shared/lib/html-context.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { BuildManifest } from '../../server/get-page-files'
import type { PageRuntime } from '../../server/config-shared'
import type { NEXT_DATA } from './utils'

import { createContext } from 'react'
Expand Down Expand Up @@ -37,7 +38,7 @@ export type HtmlProps = {
optimizeCss?: boolean
optimizeFonts?: boolean
nextScriptWorkers?: boolean
runtime?: 'edge' | 'nodejs'
runtime?: PageRuntime
hasConcurrentFeatures?: boolean
largePageDataBytes?: number
}
Expand Down
2 changes: 1 addition & 1 deletion test/integration/react-18-invalid-config/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function writeNextConfig(config, reactVersion = 17) {
describe('Invalid react 18 webpack config', () => {
it('should install react 18 when `experimental.runtime` is enabled', async () => {
writeNextConfig({
runtime: 'edge',
runtime: 'experimental-edge',
})
const { stderr } = await nextBuild(appDir, [], { stderr: true, nodeArgs })
nextConfig.restore()
Expand Down
2 changes: 1 addition & 1 deletion test/integration/react-18/app/next.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
// reactStrictMode: true,
experimental: {
// runtime: 'edge',
// runtime: 'experimental-edge',
},
images: {
deviceSizes: [480, 1024, 1600, 2000],
Expand Down
2 changes: 1 addition & 1 deletion test/integration/react-18/app/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ export default function Index() {
}

export const config = {
// runtime: 'edge'
// runtime: 'experimental-edge'
}
12 changes: 9 additions & 3 deletions test/integration/react-18/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,14 @@ function runTestsAgainstRuntime(runtime) {
if (env === 'dev') {
invalidPage.write(`export const value = 1`)
}
nextConfig.replace("// runtime: 'edge'", `runtime: '${runtime}'`)
indexPage.replace("// runtime: 'edge'", `runtime: '${runtime}'`)
nextConfig.replace(
"// runtime: 'experimental-edge'",
`runtime: '${runtime}'`
)
indexPage.replace(
"// runtime: 'experimental-edge'",
`runtime: '${runtime}'`
)
},
afterAll: (env) => {
if (env === 'dev') {
Expand All @@ -81,7 +87,7 @@ function runTestsAgainstRuntime(runtime) {
)
}

runTestsAgainstRuntime('edge')
runTestsAgainstRuntime('experimental-edge')
runTestsAgainstRuntime('nodejs')

function runTests(name, fn, opts) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ module.exports = {
pageExtensions: ['js', 'ts', 'jsx'], // .tsx won't be treat as page,
experimental: {
serverComponents: true,
runtime: 'edge',
runtime: 'experimental-edge',
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export default function MyError() {
}

export const config = {
runtime: 'edge',
runtime: 'experimental-edge',
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ export default function page() {
}

export const config = {
runtime: 'edge',
runtime: 'experimental-edge',
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ export default function Page() {
}

export const config = {
runtime: 'edge',
runtime: 'experimental-edge',
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ const Page = () => {
export default Page

export const config = {
runtime: 'edge',
runtime: 'experimental-edge',
}
Loading