From 201c7cff7e65c0c6bc9c44034ba2dba0444a4e0a Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Thu, 17 Mar 2022 17:06:52 +0100 Subject: [PATCH] Revert "Make concurrent features independent from the global runtime option (#35245)" This reverts commit 853442dfc36e37a6b1de543fef12a303364be29b. --- packages/next/build/entries.ts | 3 + packages/next/build/index.ts | 35 ++--- packages/next/build/webpack-config.ts | 13 +- packages/next/export/index.ts | 1 - packages/next/export/worker.ts | 11 +- packages/next/pages/_document.tsx | 4 +- packages/next/server/dev/hot-reloader.ts | 13 +- packages/next/server/load-components.ts | 18 +-- packages/next/server/next-server.ts | 2 +- packages/next/server/render.tsx | 15 +-- packages/next/shared/lib/html-context.ts | 1 - .../react-18-invalid-config/index.test.js | 13 ++ .../react-18/app/pages/suspense/no-preload.js | 3 +- test/integration/react-18/test/basics.js | 2 +- test/integration/react-18/test/blocking.js | 7 +- .../app/pages/err/render.js | 4 - .../app/pages/err/suspense.js | 4 - .../app/pages/next-api/image.server.js | 4 - .../app/pages/next-api/link.server.js | 4 - .../app/pages/partial-hydration.server.js | 4 - .../app/pages/routes/[dynamic].server.js | 4 - .../app/pages/streaming-rsc.server.js | 4 - .../app/pages/streaming.js | 4 - .../switchable-runtime/next.config.js | 9 -- .../switchable-runtime/package.json | 9 -- .../switchable-runtime/pages-manifest.json | 9 -- .../pages/edge-rsc.server.js | 18 --- .../switchable-runtime/pages/edge.js | 18 --- .../pages/node-rsc-ssg.server.js | 26 ---- .../pages/node-rsc-ssr.server.js | 26 ---- .../pages/node-rsc.server.js | 18 --- .../switchable-runtime/pages/node-ssg.js | 26 ---- .../switchable-runtime/pages/node-ssr.js | 26 ---- .../switchable-runtime/pages/node.js | 18 --- .../switchable-runtime/pages/static.js | 14 -- .../switchable-runtime/utils/runtime.js | 3 - .../switchable-runtime/utils/time.js | 3 - .../test/switchable-runtime.test.js | 127 ------------------ .../unsupported-native-module/next.config.js | 1 + .../unsupported-native-module/pages/index.js | 4 - 40 files changed, 60 insertions(+), 468 deletions(-) delete mode 100644 test/integration/react-streaming-and-server-components/switchable-runtime/next.config.js delete mode 100644 test/integration/react-streaming-and-server-components/switchable-runtime/package.json delete mode 100644 test/integration/react-streaming-and-server-components/switchable-runtime/pages-manifest.json delete mode 100644 test/integration/react-streaming-and-server-components/switchable-runtime/pages/edge-rsc.server.js delete mode 100644 test/integration/react-streaming-and-server-components/switchable-runtime/pages/edge.js delete mode 100644 test/integration/react-streaming-and-server-components/switchable-runtime/pages/node-rsc-ssg.server.js delete mode 100644 test/integration/react-streaming-and-server-components/switchable-runtime/pages/node-rsc-ssr.server.js delete mode 100644 test/integration/react-streaming-and-server-components/switchable-runtime/pages/node-rsc.server.js delete mode 100644 test/integration/react-streaming-and-server-components/switchable-runtime/pages/node-ssg.js delete mode 100644 test/integration/react-streaming-and-server-components/switchable-runtime/pages/node-ssr.js delete mode 100644 test/integration/react-streaming-and-server-components/switchable-runtime/pages/node.js delete mode 100644 test/integration/react-streaming-and-server-components/switchable-runtime/pages/static.js delete mode 100644 test/integration/react-streaming-and-server-components/switchable-runtime/utils/runtime.js delete mode 100644 test/integration/react-streaming-and-server-components/switchable-runtime/utils/time.js delete mode 100644 test/integration/react-streaming-and-server-components/test/switchable-runtime.test.js diff --git a/packages/next/build/entries.ts b/packages/next/build/entries.ts index c6a57df897a06..304b7047b1490 100644 --- a/packages/next/build/entries.ts +++ b/packages/next/build/entries.ts @@ -187,6 +187,9 @@ export async function getPageRuntime( if (!pageRuntime) { if (isRuntimeRequired) { pageRuntime = globalRuntimeFallback + } else { + // @TODO: Remove this branch to fully implement the RFC. + pageRuntime = globalRuntimeFallback } } diff --git a/packages/next/build/index.ts b/packages/next/build/index.ts index 3e0584d68b439..e1176656fe08d 100644 --- a/packages/next/build/index.ts +++ b/packages/next/build/index.ts @@ -76,11 +76,7 @@ import { } from '../telemetry/events' import { Telemetry } from '../telemetry/storage' import { CompilerResult, runCompiler } from './compiler' -import { - createEntrypoints, - createPagesMapping, - getPageRuntime, -} from './entries' +import { createEntrypoints, createPagesMapping } from './entries' import { generateBuildId } from './generate-build-id' import { isWriteable } from './is-writeable' import * as Log from './output/log' @@ -157,10 +153,11 @@ export default async function build( setGlobal('phase', PHASE_PRODUCTION_BUILD) setGlobal('distDir', distDir) - // We enable concurrent features (Fizz-related rendering architecture) when - // using React 18 or experimental. + // Currently, when the runtime option is set (either `nodejs` or `edge`), + // we enable concurrent features (Fizz-related rendering architecture). + const runtime = config.experimental.runtime const hasReactRoot = shouldUseReactRoot() - const hasConcurrentFeatures = hasReactRoot + const hasConcurrentFeatures = !!runtime const hasServerComponents = hasReactRoot && !!config.experimental.serverComponents @@ -625,7 +622,6 @@ export default async function build( entrypoints: entrypoints.client, rewrites, runWebpackSpan, - hasReactRoot, }), getBaseWebpackConfig(dir, { buildId, @@ -637,7 +633,6 @@ export default async function build( entrypoints: entrypoints.server, rewrites, runWebpackSpan, - hasReactRoot, }), hasReactRoot ? getBaseWebpackConfig(dir, { @@ -651,7 +646,6 @@ export default async function build( entrypoints: entrypoints.edgeServer, rewrites, runWebpackSpan, - hasReactRoot, }) : null, ]) @@ -960,22 +954,10 @@ export default async function build( let ssgPageRoutes: string[] | null = null let isMiddlewareRoute = !!page.match(MIDDLEWARE_ROUTE) - const pagePath = pagePaths.find((_path) => - _path.startsWith(actualPage + '.') - ) - const pageRuntime = - hasConcurrentFeatures && pagePath - ? await getPageRuntime( - join(pagesDir, pagePath), - config.experimental.runtime - ) - : null - if ( !isMiddlewareRoute && !isReservedPage(page) && - // We currently don't support staic optimization in the Edge runtime. - pageRuntime !== 'edge' + !hasConcurrentFeatures ) { try { let isPageStaticSpan = @@ -1501,7 +1483,10 @@ export default async function build( const combinedPages = [...staticPages, ...ssgPages] - if (combinedPages.length > 0 || useStatic404 || useDefaultStatic500) { + if ( + !hasConcurrentFeatures && + (combinedPages.length > 0 || useStatic404 || useDefaultStatic500) + ) { const staticGenerationSpan = nextBuildSpan.traceChild('static-generation') await staticGenerationSpan.traceAsyncFn(async () => { detectConflictingPaths( diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index a42abcae003e0..b07c42e17557b 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -48,6 +48,7 @@ import type { Span } from '../trace' import { getRawPageExtensions } from './utils' import browserslist from 'next/dist/compiled/browserslist' import loadJsConfig from './load-jsconfig' +import { shouldUseReactRoot } from '../server/config' import { getMiddlewareSourceMapPlugins } from './webpack/plugins/middleware-source-maps-plugin' const watchOptions = Object.freeze({ @@ -309,7 +310,6 @@ export default async function getBaseWebpackConfig( rewrites, isDevFallback = false, runWebpackSpan, - hasReactRoot, }: { buildId: string config: NextConfigComplete @@ -323,7 +323,6 @@ export default async function getBaseWebpackConfig( rewrites: CustomRoutes['rewrites'] isDevFallback?: boolean runWebpackSpan: Span - hasReactRoot: boolean } ): Promise { const { useTypeScript, jsConfig, resolvedBaseUrl } = await loadJsConfig( @@ -336,10 +335,10 @@ export default async function getBaseWebpackConfig( rewrites.afterFiles.length > 0 || rewrites.fallback.length > 0 const hasReactRefresh: boolean = dev && !isServer - + const hasReactRoot = shouldUseReactRoot() const runtime = config.experimental.runtime - // Make sure `reactRoot` is enabled when React 18 or experimental is detected. + // Make sure reactRoot is enabled when react 18 is detected if (hasReactRoot) { config.experimental.reactRoot = true } @@ -354,14 +353,14 @@ export default async function getBaseWebpackConfig( '`experimental.runtime` requires `experimental.reactRoot` to be enabled along with React 18.' ) } - if (config.experimental.serverComponents && !hasReactRoot) { + if (config.experimental.serverComponents && !runtime) { throw new Error( - '`experimental.serverComponents` requires React 18 to be installed.' + '`experimental.runtime` is required to be set along with `experimental.serverComponents`.' ) } const targetWeb = isEdgeRuntime || !isServer - const hasConcurrentFeatures = hasReactRoot + const hasConcurrentFeatures = !!runtime && hasReactRoot const hasServerComponents = hasConcurrentFeatures && !!config.experimental.serverComponents const disableOptimizedLoading = hasConcurrentFeatures diff --git a/packages/next/export/index.ts b/packages/next/export/index.ts index df995262048ee..937c01ab089cf 100644 --- a/packages/next/export/index.ts +++ b/packages/next/export/index.ts @@ -588,7 +588,6 @@ export default async function exportApp( nextConfig.experimental.disableOptimizedLoading, parentSpanId: pageExportSpan.id, httpAgentOptions: nextConfig.httpAgentOptions, - serverComponents: nextConfig.experimental.serverComponents, }) for (const validation of result.ampValidations || []) { diff --git a/packages/next/export/worker.ts b/packages/next/export/worker.ts index 3679b28eebd1d..f2e6dbb64f133 100644 --- a/packages/next/export/worker.ts +++ b/packages/next/export/worker.ts @@ -59,7 +59,6 @@ interface ExportPageInput { disableOptimizedLoading: any parentSpanId: any httpAgentOptions: NextConfigComplete['httpAgentOptions'] - serverComponents?: boolean } interface ExportPageResults { @@ -107,7 +106,6 @@ export default async function exportPage({ optimizeCss, disableOptimizedLoading, httpAgentOptions, - serverComponents, }: ExportPageInput): Promise { setHttpAgentOptions(httpAgentOptions) const exportPageSpan = trace('export-page-worker', parentSpanId) @@ -262,7 +260,7 @@ export default async function exportPage({ getServerSideProps, getStaticProps, pageConfig, - } = await loadComponents(distDir, page, serverless, serverComponents) + } = await loadComponents(distDir, page, serverless) const ampState = { ampFirst: pageConfig?.amp === true, hasQuery: Boolean(query.amp), @@ -323,12 +321,7 @@ export default async function exportPage({ throw new Error(`Failed to render serverless page`) } } else { - const components = await loadComponents( - distDir, - page, - serverless, - serverComponents - ) + const components = await loadComponents(distDir, page, serverless) const ampState = { ampFirst: components.pageConfig?.amp === true, hasQuery: Boolean(query.amp), diff --git a/packages/next/pages/_document.tsx b/packages/next/pages/_document.tsx index 72868292fa6ae..8ac37914b0026 100644 --- a/packages/next/pages/_document.tsx +++ b/packages/next/pages/_document.tsx @@ -585,9 +585,11 @@ export class Head extends Component< disableOptimizedLoading, optimizeCss, optimizeFonts, - hasConcurrentFeatures, + runtime, } = this.context + const hasConcurrentFeatures = !!runtime + const disableRuntimeJS = unstable_runtimeJS === false const disableJsPreload = unstable_JsPreload === false || !disableOptimizedLoading diff --git a/packages/next/server/dev/hot-reloader.ts b/packages/next/server/dev/hot-reloader.ts index b30f365b54ffc..bcd58454ab578 100644 --- a/packages/next/server/dev/hot-reloader.ts +++ b/packages/next/server/dev/hot-reloader.ts @@ -154,7 +154,6 @@ export default class HotReloader { private config: NextConfigComplete private runtime?: 'nodejs' | 'edge' private hasServerComponents: boolean - private hasReactRoot: boolean public clientStats: webpack5.Stats | null public serverStats: webpack5.Stats | null private clientError: Error | null = null @@ -198,9 +197,7 @@ export default class HotReloader { this.config = config this.runtime = config.experimental.runtime - this.hasReactRoot = shouldUseReactRoot() - this.hasServerComponents = - this.hasReactRoot && !!config.experimental.serverComponents + this.hasServerComponents = !!config.experimental.serverComponents this.previewProps = previewProps this.rewrites = rewrites this.hotReloaderSpan = trace('hot-reloader', undefined, { @@ -343,6 +340,8 @@ export default class HotReloader { ) ) + const hasReactRoot = shouldUseReactRoot() + return webpackConfigSpan .traceChild('generate-webpack-config') .traceAsyncFn(() => @@ -357,7 +356,6 @@ export default class HotReloader { rewrites: this.rewrites, entrypoints: entrypoints.client, runWebpackSpan: this.hotReloaderSpan, - hasReactRoot: this.hasReactRoot, }), getBaseWebpackConfig(this.dir, { dev: true, @@ -368,10 +366,9 @@ export default class HotReloader { rewrites: this.rewrites, entrypoints: entrypoints.server, runWebpackSpan: this.hotReloaderSpan, - hasReactRoot: this.hasReactRoot, }), // The edge runtime is only supported with React root. - this.hasReactRoot + hasReactRoot ? getBaseWebpackConfig(this.dir, { dev: true, isServer: true, @@ -382,7 +379,6 @@ export default class HotReloader { rewrites: this.rewrites, entrypoints: entrypoints.edgeServer, runWebpackSpan: this.hotReloaderSpan, - hasReactRoot: this.hasReactRoot, }) : null, ].filter(Boolean) as webpack.Configuration[] @@ -421,7 +417,6 @@ export default class HotReloader { this.pagesDir ) ).client, - hasReactRoot: this.hasReactRoot, }) const fallbackCompiler = webpack(fallbackConfig) diff --git a/packages/next/server/load-components.ts b/packages/next/server/load-components.ts index 361f0183899d5..ae247d9ea66fd 100644 --- a/packages/next/server/load-components.ts +++ b/packages/next/server/load-components.ts @@ -6,7 +6,6 @@ import type { import { BUILD_MANIFEST, REACT_LOADABLE_MANIFEST, - MIDDLEWARE_FLIGHT_MANIFEST, } from '../shared/lib/constants' import { join } from 'path' import { requirePage } from './require' @@ -31,7 +30,6 @@ export type LoadComponentsReturnType = { pageConfig: PageConfig buildManifest: BuildManifest reactLoadableManifest: ReactLoadableManifest - serverComponentManifest?: any | null Document: DocumentType App: AppType getStaticProps?: GetStaticProps @@ -63,8 +61,7 @@ export async function loadDefaultErrorComponents(distDir: string) { export async function loadComponents( distDir: string, pathname: string, - serverless: boolean, - serverComponents?: boolean + serverless: boolean ): Promise { if (serverless) { const ComponentMod = await requirePage(pathname, distDir, serverless) @@ -105,14 +102,10 @@ export async function loadComponents( requirePage(pathname, distDir, serverless), ]) - const [buildManifest, reactLoadableManifest, serverComponentManifest] = - await Promise.all([ - require(join(distDir, BUILD_MANIFEST)), - require(join(distDir, REACT_LOADABLE_MANIFEST)), - serverComponents - ? require(join(distDir, 'server', MIDDLEWARE_FLIGHT_MANIFEST + '.json')) - : null, - ]) + const [buildManifest, reactLoadableManifest] = await Promise.all([ + require(join(distDir, BUILD_MANIFEST)), + require(join(distDir, REACT_LOADABLE_MANIFEST)), + ]) const Component = interopDefault(ComponentMod) const Document = interopDefault(DocumentMod) @@ -132,6 +125,5 @@ export async function loadComponents( getServerSideProps, getStaticProps, getStaticPaths, - serverComponentManifest, } } diff --git a/packages/next/server/next-server.ts b/packages/next/server/next-server.ts index 2455112a313d7..83a8d7e007875 100644 --- a/packages/next/server/next-server.ts +++ b/packages/next/server/next-server.ts @@ -693,7 +693,7 @@ export default class NextNodeServer extends BaseServer { } protected getServerComponentManifest() { - if (!this.nextConfig.experimental.serverComponents) return undefined + if (!this.nextConfig.experimental.runtime) return undefined return require(join( this.distDir, 'server', diff --git a/packages/next/server/render.tsx b/packages/next/server/render.tsx index 190cfadc6b279..7797d1d654047 100644 --- a/packages/next/server/render.tsx +++ b/packages/next/server/render.tsx @@ -450,12 +450,12 @@ export async function renderToHTML( supportsDynamicHTML, images, reactRoot, - runtime: globalRuntime, + runtime, ComponentMod, AppMod, } = renderOpts - const hasConcurrentFeatures = reactRoot + const hasConcurrentFeatures = !!runtime let Document = renderOpts.Document const OriginalComponent = renderOpts.Component @@ -464,7 +464,7 @@ export async function renderToHTML( const isServerComponent = !!serverComponentManifest && hasConcurrentFeatures && - !!ComponentMod.__next_rsc__ + ComponentMod.__next_rsc__ let Component: React.ComponentType<{}> | ((props: any) => JSX.Element) = renderOpts.Component @@ -1243,7 +1243,7 @@ export async function renderToHTML( | typeof Document | undefined - if (process.browser && Document.getInitialProps) { + if (runtime === 'edge' && Document.getInitialProps) { // In the Edge runtime, `Document.getInitialProps` isn't supported. // We throw an error here if it's customized. if (!builtinDocument) { @@ -1329,8 +1329,7 @@ export async function renderToHTML( ) : ( - {isServerComponent && AppMod.__next_rsc__ ? ( - // _app.server.js is used. + {renderOpts.serverComponents && AppMod.__next_rsc__ ? ( ) : ( @@ -1362,6 +1361,7 @@ export async function renderToHTML( ), generateStaticHTML: true, }) + const flushed = await streamToString(flushEffectStream) return flushed } @@ -1489,8 +1489,7 @@ export async function renderToHTML( optimizeCss: renderOpts.optimizeCss, optimizeFonts: renderOpts.optimizeFonts, nextScriptWorkers: renderOpts.nextScriptWorkers, - runtime: globalRuntime, - hasConcurrentFeatures, + runtime, } const document = ( diff --git a/packages/next/shared/lib/html-context.ts b/packages/next/shared/lib/html-context.ts index b069fca0f49f9..0a4455715361e 100644 --- a/packages/next/shared/lib/html-context.ts +++ b/packages/next/shared/lib/html-context.ts @@ -38,7 +38,6 @@ export type HtmlProps = { optimizeFonts?: boolean nextScriptWorkers?: boolean runtime?: 'edge' | 'nodejs' - hasConcurrentFeatures?: boolean } export const HtmlContext = createContext(null as any) diff --git a/test/integration/react-18-invalid-config/index.test.js b/test/integration/react-18-invalid-config/index.test.js index 9372f0f199f4d..e0096a0b35023 100644 --- a/test/integration/react-18-invalid-config/index.test.js +++ b/test/integration/react-18-invalid-config/index.test.js @@ -25,6 +25,19 @@ describe('Invalid react 18 webpack config', () => { ) }) + it('should require `experimental.runtime` for server components', async () => { + writeNextConfig({ + reactRoot: true, + serverComponents: true, + }) + const { stderr } = await nextBuild(appDir, [], { stderr: true }) + nextConfig.restore() + + expect(stderr).toContain( + '`experimental.runtime` is required to be set along with `experimental.serverComponents`.' + ) + }) + it('should warn user when not using react 18 and `experimental.reactRoot` is enabled', async () => { const reactDomPackagePah = join(appDir, 'node_modules/react-dom') await fs.mkdirp(reactDomPackagePah) diff --git a/test/integration/react-18/app/pages/suspense/no-preload.js b/test/integration/react-18/app/pages/suspense/no-preload.js index 8ae8c7c599f2e..aaf54e244118f 100644 --- a/test/integration/react-18/app/pages/suspense/no-preload.js +++ b/test/integration/react-18/app/pages/suspense/no-preload.js @@ -2,7 +2,6 @@ import { Suspense } from 'react' import dynamic from 'next/dynamic' const Bar = dynamic(() => import('../../components/bar'), { - ssr: false, suspense: true, // Explicitly declare loaded modules. // For suspense cases, they'll be ignored. @@ -15,7 +14,7 @@ const Bar = dynamic(() => import('../../components/bar'), { export default function NoPreload() { return ( - + ) diff --git a/test/integration/react-18/test/basics.js b/test/integration/react-18/test/basics.js index bc63d2ad4f0f5..debbad85a56b5 100644 --- a/test/integration/react-18/test/basics.js +++ b/test/integration/react-18/test/basics.js @@ -31,7 +31,7 @@ export default (context) => { const nextData = JSON.parse($('#__NEXT_DATA__').text()) const content = $('#__next').text() // is suspended - expect(content).toBe('fallback') + expect(content).toBe('rab') expect(nextData.dynamicIds).toBeUndefined() }) diff --git a/test/integration/react-18/test/blocking.js b/test/integration/react-18/test/blocking.js index 0db4aacd6cf97..c4feeb2e8a301 100644 --- a/test/integration/react-18/test/blocking.js +++ b/test/integration/react-18/test/blocking.js @@ -8,16 +8,15 @@ export default (context, render) => { return cheerio.load(html) } - it('should render fallback on server side if suspense without ssr', async () => { + it('should render fallback on server side if suspense without preload', async () => { const $ = await get$('/suspense/no-preload') const nextData = JSON.parse($('#__NEXT_DATA__').text()) const content = $('#__next').text() - expect(content).toBe('fallback') + expect(content).toBe('rab') expect(nextData.dynamicIds).toBeUndefined() }) - // Testing the same thing as above. - it.skip('should render import fallback on server side if suspended without ssr', async () => { + it('should render fallback on server side if suspended on server with preload', async () => { const $ = await get$('/suspense/thrown') const html = $('body').html() expect(html).toContain('loading') diff --git a/test/integration/react-streaming-and-server-components/app/pages/err/render.js b/test/integration/react-streaming-and-server-components/app/pages/err/render.js index 7d9d321f7cb0a..0c6ec0bd1baed 100644 --- a/test/integration/react-streaming-and-server-components/app/pages/err/render.js +++ b/test/integration/react-streaming-and-server-components/app/pages/err/render.js @@ -5,7 +5,3 @@ export default function MyError() { throw new Error('oops') } } - -export const config = { - runtime: 'edge', -} diff --git a/test/integration/react-streaming-and-server-components/app/pages/err/suspense.js b/test/integration/react-streaming-and-server-components/app/pages/err/suspense.js index 05f85b9f4b16f..e23ccd094bbab 100644 --- a/test/integration/react-streaming-and-server-components/app/pages/err/suspense.js +++ b/test/integration/react-streaming-and-server-components/app/pages/err/suspense.js @@ -18,7 +18,3 @@ export default function page() { ) } - -export const config = { - runtime: 'edge', -} diff --git a/test/integration/react-streaming-and-server-components/app/pages/next-api/image.server.js b/test/integration/react-streaming-and-server-components/app/pages/next-api/image.server.js index 96c50ace36a55..0083c3b9d4ccb 100644 --- a/test/integration/react-streaming-and-server-components/app/pages/next-api/image.server.js +++ b/test/integration/react-streaming-and-server-components/app/pages/next-api/image.server.js @@ -7,7 +7,3 @@ const Page = () => { } export default Page - -export const config = { - runtime: 'edge', -} diff --git a/test/integration/react-streaming-and-server-components/app/pages/next-api/link.server.js b/test/integration/react-streaming-and-server-components/app/pages/next-api/link.server.js index 1162cea6f999c..a4d5cb765082c 100644 --- a/test/integration/react-streaming-and-server-components/app/pages/next-api/link.server.js +++ b/test/integration/react-streaming-and-server-components/app/pages/next-api/link.server.js @@ -16,7 +16,3 @@ export default function LinkPage({ router }) { ) } - -export const config = { - runtime: 'edge', -} diff --git a/test/integration/react-streaming-and-server-components/app/pages/partial-hydration.server.js b/test/integration/react-streaming-and-server-components/app/pages/partial-hydration.server.js index 8604f3bdcb726..c3740b8719fed 100644 --- a/test/integration/react-streaming-and-server-components/app/pages/partial-hydration.server.js +++ b/test/integration/react-streaming-and-server-components/app/pages/partial-hydration.server.js @@ -40,7 +40,3 @@ export default function () { ) } - -export const config = { - runtime: 'edge', -} diff --git a/test/integration/react-streaming-and-server-components/app/pages/routes/[dynamic].server.js b/test/integration/react-streaming-and-server-components/app/pages/routes/[dynamic].server.js index 27c7c0bddf028..288d6165f9990 100644 --- a/test/integration/react-streaming-and-server-components/app/pages/routes/[dynamic].server.js +++ b/test/integration/react-streaming-and-server-components/app/pages/routes/[dynamic].server.js @@ -1,7 +1,3 @@ export default function Pid({ router }) { return
{`query: ${router.query.dynamic}`}
} - -export const config = { - runtime: 'edge', -} diff --git a/test/integration/react-streaming-and-server-components/app/pages/streaming-rsc.server.js b/test/integration/react-streaming-and-server-components/app/pages/streaming-rsc.server.js index 7d7c0cacce37b..c6653c9e71f81 100644 --- a/test/integration/react-streaming-and-server-components/app/pages/streaming-rsc.server.js +++ b/test/integration/react-streaming-and-server-components/app/pages/streaming-rsc.server.js @@ -29,7 +29,3 @@ export default function Page() { ) } - -export const config = { - runtime: 'edge', -} diff --git a/test/integration/react-streaming-and-server-components/app/pages/streaming.js b/test/integration/react-streaming-and-server-components/app/pages/streaming.js index 70aaf4ced70ef..ac58f5e9e2c38 100644 --- a/test/integration/react-streaming-and-server-components/app/pages/streaming.js +++ b/test/integration/react-streaming-and-server-components/app/pages/streaming.js @@ -21,7 +21,3 @@ export default function Page() {
) } - -export const config = { - runtime: 'edge', -} diff --git a/test/integration/react-streaming-and-server-components/switchable-runtime/next.config.js b/test/integration/react-streaming-and-server-components/switchable-runtime/next.config.js deleted file mode 100644 index 7b4ccb839cd64..0000000000000 --- a/test/integration/react-streaming-and-server-components/switchable-runtime/next.config.js +++ /dev/null @@ -1,9 +0,0 @@ -const withReact18 = require('../../react-18/test/with-react-18') - -module.exports = withReact18({ - reactStrictMode: true, - experimental: { - serverComponents: true, - // runtime: 'edge', - }, -}) diff --git a/test/integration/react-streaming-and-server-components/switchable-runtime/package.json b/test/integration/react-streaming-and-server-components/switchable-runtime/package.json deleted file mode 100644 index 90af0ce830c99..0000000000000 --- a/test/integration/react-streaming-and-server-components/switchable-runtime/package.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "private": true, - "scripts": { - "lnext": "node -r ../../react-18/test/require-hook.js ../../../../packages/next/dist/bin/next", - "dev": "yarn lnext dev", - "build": "yarn lnext build", - "start": "yarn lnext start" - } -} diff --git a/test/integration/react-streaming-and-server-components/switchable-runtime/pages-manifest.json b/test/integration/react-streaming-and-server-components/switchable-runtime/pages-manifest.json deleted file mode 100644 index 4aa797aeaee30..0000000000000 --- a/test/integration/react-streaming-and-server-components/switchable-runtime/pages-manifest.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "/_app": "pages/_app.js", - "/_error": "pages/_error.js", - "/edge-rsc": "pages/edge-rsc.js", - "/static": "pages/static.js", - "/node-rsc": "pages/node-rsc.js", - "/node": "pages/node.js", - "/edge": "pages/edge.js" -} diff --git a/test/integration/react-streaming-and-server-components/switchable-runtime/pages/edge-rsc.server.js b/test/integration/react-streaming-and-server-components/switchable-runtime/pages/edge-rsc.server.js deleted file mode 100644 index 83dc8c219e84e..0000000000000 --- a/test/integration/react-streaming-and-server-components/switchable-runtime/pages/edge-rsc.server.js +++ /dev/null @@ -1,18 +0,0 @@ -import getRuntime from '../utils/runtime' -import getTime from '../utils/time' - -export default function Page() { - return ( -
- This is a SSR RSC page. -
- {'Runtime: ' + getRuntime()} -
- {'Time: ' + getTime()} -
- ) -} - -export const config = { - runtime: 'edge', -} diff --git a/test/integration/react-streaming-and-server-components/switchable-runtime/pages/edge.js b/test/integration/react-streaming-and-server-components/switchable-runtime/pages/edge.js deleted file mode 100644 index c3425c7e64af7..0000000000000 --- a/test/integration/react-streaming-and-server-components/switchable-runtime/pages/edge.js +++ /dev/null @@ -1,18 +0,0 @@ -import getRuntime from '../utils/runtime' -import getTime from '../utils/time' - -export default function Page() { - return ( -
- This is a SSR page. -
- {'Runtime: ' + getRuntime()} -
- {'Time: ' + getTime()} -
- ) -} - -export const config = { - runtime: 'edge', -} diff --git a/test/integration/react-streaming-and-server-components/switchable-runtime/pages/node-rsc-ssg.server.js b/test/integration/react-streaming-and-server-components/switchable-runtime/pages/node-rsc-ssg.server.js deleted file mode 100644 index 362e634644eb2..0000000000000 --- a/test/integration/react-streaming-and-server-components/switchable-runtime/pages/node-rsc-ssg.server.js +++ /dev/null @@ -1,26 +0,0 @@ -import getRuntime from '../utils/runtime' -import getTime from '../utils/time' - -export default function Page({ type }) { - return ( -
- This is a {type} RSC page. -
- {'Runtime: ' + getRuntime()} -
- {'Time: ' + getTime()} -
- ) -} - -export function getStaticProps() { - return { - props: { - type: 'SSG', - }, - } -} - -export const config = { - runtime: 'nodejs', -} diff --git a/test/integration/react-streaming-and-server-components/switchable-runtime/pages/node-rsc-ssr.server.js b/test/integration/react-streaming-and-server-components/switchable-runtime/pages/node-rsc-ssr.server.js deleted file mode 100644 index 1b8b01526a3ce..0000000000000 --- a/test/integration/react-streaming-and-server-components/switchable-runtime/pages/node-rsc-ssr.server.js +++ /dev/null @@ -1,26 +0,0 @@ -import getRuntime from '../utils/runtime' -import getTime from '../utils/time' - -export default function Page({ type }) { - return ( -
- This is a {type} RSC page. -
- {'Runtime: ' + getRuntime()} -
- {'Time: ' + getTime()} -
- ) -} - -export function getServerSideProps() { - return { - props: { - type: 'SSR', - }, - } -} - -export const config = { - runtime: 'nodejs', -} diff --git a/test/integration/react-streaming-and-server-components/switchable-runtime/pages/node-rsc.server.js b/test/integration/react-streaming-and-server-components/switchable-runtime/pages/node-rsc.server.js deleted file mode 100644 index f3563039b63bd..0000000000000 --- a/test/integration/react-streaming-and-server-components/switchable-runtime/pages/node-rsc.server.js +++ /dev/null @@ -1,18 +0,0 @@ -import getRuntime from '../utils/runtime' -import getTime from '../utils/time' - -export default function Page() { - return ( -
- This is a static RSC page. -
- {'Runtime: ' + getRuntime()} -
- {'Time: ' + getTime()} -
- ) -} - -export const config = { - runtime: 'nodejs', -} diff --git a/test/integration/react-streaming-and-server-components/switchable-runtime/pages/node-ssg.js b/test/integration/react-streaming-and-server-components/switchable-runtime/pages/node-ssg.js deleted file mode 100644 index d555009acfcdb..0000000000000 --- a/test/integration/react-streaming-and-server-components/switchable-runtime/pages/node-ssg.js +++ /dev/null @@ -1,26 +0,0 @@ -import getRuntime from '../utils/runtime' -import getTime from '../utils/time' - -export default function Page({ type }) { - return ( -
- This is a {type} page. -
- {'Runtime: ' + getRuntime()} -
- {'Time: ' + getTime()} -
- ) -} - -export function getStaticProps() { - return { - props: { - type: 'SSG', - }, - } -} - -export const config = { - runtime: 'nodejs', -} diff --git a/test/integration/react-streaming-and-server-components/switchable-runtime/pages/node-ssr.js b/test/integration/react-streaming-and-server-components/switchable-runtime/pages/node-ssr.js deleted file mode 100644 index e58276b47a763..0000000000000 --- a/test/integration/react-streaming-and-server-components/switchable-runtime/pages/node-ssr.js +++ /dev/null @@ -1,26 +0,0 @@ -import getRuntime from '../utils/runtime' -import getTime from '../utils/time' - -export default function Page({ type }) { - return ( -
- This is a {type} page. -
- {'Runtime: ' + getRuntime()} -
- {'Time: ' + getTime()} -
- ) -} - -export function getServerSideProps() { - return { - props: { - type: 'SSR', - }, - } -} - -export const config = { - runtime: 'nodejs', -} diff --git a/test/integration/react-streaming-and-server-components/switchable-runtime/pages/node.js b/test/integration/react-streaming-and-server-components/switchable-runtime/pages/node.js deleted file mode 100644 index bf065da478ba8..0000000000000 --- a/test/integration/react-streaming-and-server-components/switchable-runtime/pages/node.js +++ /dev/null @@ -1,18 +0,0 @@ -import getRuntime from '../utils/runtime' -import getTime from '../utils/time' - -export default function Page() { - return ( -
- This is a static page. -
- {'Runtime: ' + getRuntime()} -
- {'Time: ' + getTime()} -
- ) -} - -export const config = { - runtime: 'nodejs', -} diff --git a/test/integration/react-streaming-and-server-components/switchable-runtime/pages/static.js b/test/integration/react-streaming-and-server-components/switchable-runtime/pages/static.js deleted file mode 100644 index e44edfd795232..0000000000000 --- a/test/integration/react-streaming-and-server-components/switchable-runtime/pages/static.js +++ /dev/null @@ -1,14 +0,0 @@ -import getRuntime from '../utils/runtime' -import getTime from '../utils/time' - -export default function Page() { - return ( -
- This is a static page. -
- {'Runtime: ' + getRuntime()} -
- {'Time: ' + getTime()} -
- ) -} diff --git a/test/integration/react-streaming-and-server-components/switchable-runtime/utils/runtime.js b/test/integration/react-streaming-and-server-components/switchable-runtime/utils/runtime.js deleted file mode 100644 index 444f1ee8b498b..0000000000000 --- a/test/integration/react-streaming-and-server-components/switchable-runtime/utils/runtime.js +++ /dev/null @@ -1,3 +0,0 @@ -export default function getRuntime() { - return process.version ? `Node.js ${process.version}` : 'Edge/Browser' -} diff --git a/test/integration/react-streaming-and-server-components/switchable-runtime/utils/time.js b/test/integration/react-streaming-and-server-components/switchable-runtime/utils/time.js deleted file mode 100644 index cf78549b9a7c1..0000000000000 --- a/test/integration/react-streaming-and-server-components/switchable-runtime/utils/time.js +++ /dev/null @@ -1,3 +0,0 @@ -export default function getTime() { - return Date.now() -} diff --git a/test/integration/react-streaming-and-server-components/test/switchable-runtime.test.js b/test/integration/react-streaming-and-server-components/test/switchable-runtime.test.js deleted file mode 100644 index 62ebdcadf4264..0000000000000 --- a/test/integration/react-streaming-and-server-components/test/switchable-runtime.test.js +++ /dev/null @@ -1,127 +0,0 @@ -/* eslint-env jest */ - -import { join } from 'path' -import { - // File, - nextBuild as _nextBuild, - nextStart as _nextStart, -} from 'next-test-utils' - -import { findPort, killApp, renderViaHTTP } from 'next-test-utils' - -const nodeArgs = ['-r', join(__dirname, '../../react-18/test/require-hook.js')] - -const appDir = join(__dirname, '../switchable-runtime') -// const nextConfig = new File(join(appDir, 'next.config.js')) - -async function nextBuild(dir, options) { - return await _nextBuild(dir, [], { - ...options, - stdout: true, - stderr: true, - nodeArgs, - }) -} - -async function nextStart(dir, port) { - return await _nextStart(dir, port, { - stdout: true, - stderr: true, - nodeArgs, - }) -} - -async function testRoute(appPort, url, { isStatic, isEdge }) { - const html1 = await renderViaHTTP(appPort, url) - const renderedAt1 = +html1.match(/Time: (\d+)/)[1] - expect(html1).toContain(`Runtime: ${isEdge ? 'Edge' : 'Node.js'}`) - - const html2 = await renderViaHTTP(appPort, url) - const renderedAt2 = +html2.match(/Time: (\d+)/)[1] - expect(html2).toContain(`Runtime: ${isEdge ? 'Edge' : 'Node.js'}`) - - if (isStatic) { - // Should not be re-rendered, some timestamp should be returned. - expect(renderedAt1).toBe(renderedAt2) - } else { - // Should be re-rendered. - expect(renderedAt1).toBeLessThan(renderedAt2) - } -} - -describe('Without global runtime configuration', () => { - const context = { appDir } - - beforeAll(async () => { - context.appPort = await findPort() - const { stderr } = await nextBuild(context.appDir) - context.stderr = stderr - context.server = await nextStart(context.appDir, context.appPort) - }) - afterAll(async () => { - await killApp(context.server) - }) - - it('should build /static as a static page with the nodejs runtime', async () => { - await testRoute(context.appPort, '/static', { - isStatic: true, - isEdge: false, - }) - }) - - it('should build /node as a static page with the nodejs runtime', async () => { - await testRoute(context.appPort, '/node', { - isStatic: true, - isEdge: false, - }) - }) - - it('should build /node-ssr as a dynamic page with the nodejs runtime', async () => { - await testRoute(context.appPort, '/node-ssr', { - isStatic: false, - isEdge: false, - }) - }) - - it('should build /node-ssg as a static page with the nodejs runtime', async () => { - await testRoute(context.appPort, '/node-ssg', { - isStatic: true, - isEdge: false, - }) - }) - - it('should build /node-rsc as a static page with the nodejs runtime', async () => { - await testRoute(context.appPort, '/node-rsc', { - isStatic: true, - isEdge: false, - }) - }) - - it('should build /node-rsc-ssr as a dynamic page with the nodejs runtime', async () => { - await testRoute(context.appPort, '/node-rsc-ssr', { - isStatic: false, - isEdge: false, - }) - }) - - it('should build /node-rsc-ssg as a static page with the nodejs runtime', async () => { - await testRoute(context.appPort, '/node-rsc-ssg', { - isStatic: true, - isEdge: false, - }) - }) - - it('should build /edge as a dynamic page with the edge runtime', async () => { - await testRoute(context.appPort, '/edge', { - isStatic: false, - isEdge: true, - }) - }) - - it('should build /edge-rsc as a dynamic page with the edge runtime', async () => { - await testRoute(context.appPort, '/edge-rsc', { - isStatic: false, - isEdge: true, - }) - }) -}) diff --git a/test/integration/react-streaming-and-server-components/unsupported-native-module/next.config.js b/test/integration/react-streaming-and-server-components/unsupported-native-module/next.config.js index deb87bcba88d7..4783ccbdadb78 100644 --- a/test/integration/react-streaming-and-server-components/unsupported-native-module/next.config.js +++ b/test/integration/react-streaming-and-server-components/unsupported-native-module/next.config.js @@ -3,6 +3,7 @@ const withReact18 = require('../../react-18/test/with-react-18') module.exports = withReact18({ experimental: { reactRoot: true, + runtime: 'edge', serverComponents: true, }, }) diff --git a/test/integration/react-streaming-and-server-components/unsupported-native-module/pages/index.js b/test/integration/react-streaming-and-server-components/unsupported-native-module/pages/index.js index 8371b4c194f7d..31f0f204a9d3b 100644 --- a/test/integration/react-streaming-and-server-components/unsupported-native-module/pages/index.js +++ b/test/integration/react-streaming-and-server-components/unsupported-native-module/pages/index.js @@ -8,7 +8,3 @@ export default function Index() { console.log(EOF) return 'Access Node.js native module dns' } - -export const config = { - runtime: 'edge', -}