Skip to content

Commit

Permalink
Add export runtime test for pages and fully remove experimental.runti…
Browse files Browse the repository at this point in the history
…me (#48630)

### What 

`export const runtime = 'experimental-edge'` also work for pages. This
PR add tests for that.

Closes NEXT-426

Follow up for #46631 that to fully remove all related code of the
`experimental.runtime`
  • Loading branch information
huozhi authored Apr 20, 2023
1 parent 682fb27 commit cc684d0
Show file tree
Hide file tree
Showing 28 changed files with 82 additions and 267 deletions.
13 changes: 6 additions & 7 deletions packages/next/src/build/analysis/get-page-static-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ function warnAboutUnsupportedValue(
* Related discussion: https://github.com/vercel/next.js/discussions/34179
*/
export async function getPageStaticInfo(params: {
nextConfig: Partial<NextConfig>
pageFilePath: string
nextConfig: Partial<NextConfig>
isDev?: boolean
page?: string
pageType: 'pages' | 'app' | 'root'
Expand Down Expand Up @@ -382,11 +382,10 @@ export async function getPageStaticInfo(params: {

const isAnAPIRoute = isAPIRoute(page?.replace(/^(?:\/src)?\/pages\//, '/'))

resolvedRuntime = isEdgeRuntime(resolvedRuntime)
? resolvedRuntime
: requiresServerRuntime
? resolvedRuntime || nextConfig.experimental?.runtime
: undefined
resolvedRuntime =
isEdgeRuntime(resolvedRuntime) || requiresServerRuntime
? resolvedRuntime
: undefined

if (resolvedRuntime === SERVER_RUNTIME.experimentalEdge) {
warnAboutExperimentalEdge(isAnAPIRoute ? page! : null)
Expand Down Expand Up @@ -425,6 +424,6 @@ export async function getPageStaticInfo(params: {
ssr: false,
ssg: false,
rsc: RSC_MODULE_TYPES.server,
runtime: nextConfig.experimental?.runtime,
runtime: undefined,
}
}
5 changes: 4 additions & 1 deletion packages/next/src/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,10 @@ export default async function getBaseWebpackConfig(
const enableTypedRoutes = !!config.experimental.typedRoutes && hasAppDir

if (isClient) {
if (isEdgeRuntime(config.experimental.runtime)) {
if (
// @ts-expect-error: experimental.runtime is deprecated
isEdgeRuntime(config.experimental.runtime)
) {
Log.warn(
'You are using `experimental.runtime` which was removed. Check https://nextjs.org/docs/api-routes/edge-api-routes on how to use edge runtime.'
)
Expand Down
6 changes: 0 additions & 6 deletions packages/next/src/server/config-schema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { NextConfig } from './config'
import type { JSONSchemaType } from 'ajv'
import { VALID_LOADERS } from '../shared/lib/image-config'
import { SERVER_RUNTIME } from '../lib/constants'

const configSchema = {
type: 'object',
Expand Down Expand Up @@ -373,11 +372,6 @@ const configSchema = {
minimum: 0,
type: 'number',
},
runtime: {
// automatic typing doesn't like enum
enum: Object.values(SERVER_RUNTIME) as any,
type: 'string',
},
serverComponentsExternalPackages: {
items: {
type: 'string',
Expand Down
3 changes: 0 additions & 3 deletions packages/next/src/server/config-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
ImageConfigComplete,
imageConfigDefault,
} from '../shared/lib/image-config'
import { ServerRuntime } from 'next/types'
import { SubresourceIntegrityAlgorithm } from '../build/webpack/plugins/subresource-integrity-plugin'
import { WEB_VITALS } from '../shared/lib/utils'
import type { NextParsedUrlQuery } from './request-meta'
Expand Down Expand Up @@ -195,7 +194,6 @@ export interface ExperimentalConfig {
craCompat?: boolean
esmExternals?: boolean | 'loose'
isrMemoryCacheSize?: number
runtime?: Exclude<ServerRuntime, undefined>
fullySpecified?: boolean
urlImports?: NonNullable<webpack.Configuration['experiments']>['buildHttp']
outputFileTracingRoot?: string
Expand Down Expand Up @@ -662,7 +660,6 @@ export const defaultConfig: NextConfig = {
fetchCacheKeyPrefix: '',
middlewarePrefetch: 'flexible',
optimisticClientCache: true,
runtime: undefined,
manualClientBasePath: false,
legacyBrowsers: false,
newNextLinkBehavior: true,
Expand Down
4 changes: 1 addition & 3 deletions test/.stats-app/pages/edge-ssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ export default function page() {
return 'edge-ssr'
}

export const config = {
runtime: 'experimental-edge',
}
export const runtime = 'experimental-edge'
1 change: 0 additions & 1 deletion test/e2e/app-dir/app-edge-global/.gitignore

This file was deleted.

15 changes: 0 additions & 15 deletions test/e2e/app-dir/app-edge-global/app-edge-global.test.ts

This file was deleted.

11 changes: 0 additions & 11 deletions test/e2e/app-dir/app-edge-global/app/app-edge/layout.tsx

This file was deleted.

6 changes: 0 additions & 6 deletions test/e2e/app-dir/app-edge-global/app/app-edge/page.tsx

This file was deleted.

8 changes: 0 additions & 8 deletions test/e2e/app-dir/app-edge-global/app/layout.tsx

This file was deleted.

6 changes: 0 additions & 6 deletions test/e2e/app-dir/app-edge-global/next.config.js

This file was deleted.

29 changes: 0 additions & 29 deletions test/e2e/app-dir/app-edge-global/tsconfig.json

This file was deleted.

2 changes: 1 addition & 1 deletion test/e2e/app-dir/app-edge/pages/pages-edge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export default function Page() {
return <p>pages-edge-ssr</p>
}

export const config = { runtime: 'experimental-edge' }
export const runtime = 'experimental-edge'
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export const config = {
runtime: 'edge',
}
export const runtime = 'experimental-edge'

export default (req) => {
return Response.json(Object.fromEntries(req.headers.entries()), {
Expand Down
4 changes: 1 addition & 3 deletions test/e2e/app-dir/app/pages/api/hello.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ export default function api(req) {
return new Response('hello')
}

export const config = {
runtime: 'edge',
}
export const runtime = 'edge'
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import B from 'node:buffer'
import B2 from 'buffer'
import { NextResponse } from 'next/server'

export const config = { runtime: 'edge' }
export const runtime = 'edge'

/**
* @param {Request} req
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app-dir/set-cookies/pages/api/pages/edge.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const config = { runtime: 'edge' }
export const runtime = 'edge'

import cookies from '../../../cookies'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const config = { runtime: 'experimental-edge' }

import cookies from '../../../cookies'

export const runtime = 'edge'

export default async function handler() {
const headers = new Headers()
for (const cookie of cookies) {
Expand Down
3 changes: 0 additions & 3 deletions test/e2e/streaming-ssr/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,6 @@ if (isNextProd) {
}`,
},
nextConfig: {
experimental: {
runtime: 'nodejs',
},
webpack(config, { nextRuntime }) {
const path = require('path')
const fs = require('fs')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@ module.exports = {
loader: 'custom',
loaderFile: './dummy-loader.js',
},
experimental: {
runtime: 'experimental-edge',
},
}
5 changes: 1 addition & 4 deletions test/integration/react-18/app/next.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
module.exports = {
// reactStrictMode: true,
experimental: {
// runtime: 'experimental-edge',
},
reactStrictMode: true,
images: {
deviceSizes: [480, 1024, 1600, 2000],
imageSizes: [16, 32, 48, 64],
Expand Down
56 changes: 2 additions & 54 deletions test/integration/react-18/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,24 @@

import { join } from 'path'

import {
File,
findPort,
killApp,
launchApp,
renderViaHTTP,
hasRedbox,
getRedboxHeader,
runDevSuite,
runProdSuite,
} from 'next-test-utils'
import { File, renderViaHTTP, runDevSuite, runProdSuite } from 'next-test-utils'
import concurrent from './concurrent'
import basics from './basics'
import strictMode from './strict-mode'
import webdriver from 'next-webdriver'

const appDir = join(__dirname, '../app')
const nextConfig = new File(join(appDir, 'next.config.js'))
const invalidPage = new File(join(appDir, 'pages/invalid.js'))
const indexPage = new File(join(appDir, 'pages/index.js'))

describe('Basics', () => {
runTests('default setting with react 18', basics)
})

// React 18 with Strict Mode enabled might cause double invocation of lifecycle methods.
describe('Strict mode - dev', () => {
const context = { appDir }

beforeAll(async () => {
nextConfig.replace('// reactStrictMode: true,', 'reactStrictMode: true,')
context.appPort = await findPort()
context.server = await launchApp(context.appDir, context.appPort)
})

afterAll(() => {
nextConfig.restore()
killApp(context.server)
})

strictMode(context)
})

function runTestsAgainstRuntime(runtime) {
runTests(
`Concurrent mode in the ${runtime} runtime`,
(context, env) => {
concurrent(context, (p, q) => renderViaHTTP(context.appPort, p, q))

if (env === 'dev') {
it('should recover after undefined exported as default', async () => {
const browser = await webdriver(context.appPort, '/invalid')

expect(await hasRedbox(browser, true)).toBe(true)
expect(await getRedboxHeader(browser)).toMatch(
`Error: The default export is not a React Component in page: "/invalid"`
)
})
}
strictMode(context)

it('should not have invalid config warning', async () => {
await renderViaHTTP(context.appPort, '/')
Expand All @@ -69,23 +28,12 @@ function runTestsAgainstRuntime(runtime) {
},
{
beforeAll: (env) => {
if (env === 'dev') {
invalidPage.write(`export const value = 1`)
}
nextConfig.replace(
"// runtime: 'experimental-edge'",
`runtime: '${runtime}'`
)
indexPage.replace(
"// runtime: 'experimental-edge'",
`runtime: '${runtime}'`
)
},
afterAll: (env) => {
if (env === 'dev') {
invalidPage.delete()
}
nextConfig.restore()
indexPage.restore()
},
}
Expand Down
10 changes: 0 additions & 10 deletions test/integration/react-streaming/app/next.config.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Suspense } from 'react'

let result
let promise
function Data() {
if (result) return result
if (!promise)
promise = new Promise((res) => {
setTimeout(() => {
result = 'next_streaming_data'
res()
}, 500)
})
throw promise
}

export default function Page() {
return (
<Suspense fallback="next_streaming_fallback">
<Data />
</Suspense>
)
}

export const runtime = 'experimental-edge'
1 change: 1 addition & 0 deletions test/integration/react-streaming/app/pages/streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default function Page() {
)
}

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

0 comments on commit cc684d0

Please sign in to comment.