Add additional handling for experimental-compile (#56224)

This ensures we properly set the `isReady` flag when building with `experimental-compile` and enables our main app dir test suite to ensure we don't regress on it.
This commit is contained in:
JJ Kasper 2023-09-29 15:11:45 -07:00 committed by GitHub
parent 61180cfc84
commit e78eee25c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 64 additions and 153 deletions

View file

@ -4,8 +4,5 @@
"repository": { "repository": {
"url": "vercel/next.js", "url": "vercel/next.js",
"directory": "packages/next-plugin-storybook" "directory": "packages/next-plugin-storybook"
},
"peerDependencies": {
"next": "*"
} }
} }

View file

@ -2290,6 +2290,10 @@ export default abstract class Server<ServerOptions extends Options = Options> {
const isPageIncludedInStaticPaths = const isPageIncludedInStaticPaths =
staticPathKey && staticPaths?.includes(staticPathKey) staticPathKey && staticPaths?.includes(staticPathKey)
if ((this.nextConfig.experimental as any).isExperimentalCompile) {
fallbackMode = 'blocking'
}
// When we did not respond from cache, we need to choose to block on // When we did not respond from cache, we need to choose to block on
// rendering or return a skeleton. // rendering or return a skeleton.
// //

View file

@ -13,9 +13,12 @@ import './node-polyfill-crypto'
import { default as Server } from './next-server' import { default as Server } from './next-server'
import * as log from '../build/output/log' import * as log from '../build/output/log'
import loadConfig from './config' import loadConfig from './config'
import { resolve } from 'path' import path, { resolve } from 'path'
import { NON_STANDARD_NODE_ENV } from '../lib/constants' import { NON_STANDARD_NODE_ENV } from '../lib/constants'
import { PHASE_DEVELOPMENT_SERVER } from '../shared/lib/constants' import {
PHASE_DEVELOPMENT_SERVER,
SERVER_FILES_MANIFEST,
} from '../shared/lib/constants'
import { PHASE_PRODUCTION_SERVER } from '../shared/lib/constants' import { PHASE_PRODUCTION_SERVER } from '../shared/lib/constants'
import { getTracer } from './lib/trace/tracer' import { getTracer } from './lib/trace/tracer'
import { NextServerSpan } from './lib/trace/constants' import { NextServerSpan } from './lib/trace/constants'
@ -163,17 +166,39 @@ export class NextServer {
} }
private async [SYMBOL_LOAD_CONFIG]() { private async [SYMBOL_LOAD_CONFIG]() {
return ( const dir = resolve(this.options.dir || '.')
const config =
this.options.preloadedConfig || this.options.preloadedConfig ||
loadConfig( (await loadConfig(
this.options.dev ? PHASE_DEVELOPMENT_SERVER : PHASE_PRODUCTION_SERVER, this.options.dev ? PHASE_DEVELOPMENT_SERVER : PHASE_PRODUCTION_SERVER,
resolve(this.options.dir || '.'), dir,
{ {
customConfig: this.options.conf, customConfig: this.options.conf,
silent: true, silent: true,
} }
) ))
)
// check serialized build config when available
if (process.env.NODE_ENV === 'production') {
try {
const serializedConfig = require(path.join(
dir,
'.next',
SERVER_FILES_MANIFEST
)).config
// @ts-expect-error internal field
config.experimental.isExperimentalConfig =
serializedConfig.experimental.isExperimentalCompile
} catch (_) {
// if distDir is customized we don't know until we
// load the config so fallback to loading the config
// from next.config.js
}
}
return config
} }
private async getServer() { private async getServer() {

View file

@ -495,7 +495,7 @@ export async function renderToHTMLImpl(
) )
} }
const isAutoExport = let isAutoExport =
!hasPageGetInitialProps && !hasPageGetInitialProps &&
defaultAppGetInitialProps && defaultAppGetInitialProps &&
!isSSG && !isSSG &&
@ -511,6 +511,7 @@ export async function renderToHTMLImpl(
private: false, private: false,
stateful: false, stateful: false,
}) })
isAutoExport = false
} }
if (hasPageGetInitialProps && isSSG) { if (hasPageGetInitialProps && isSSG) {
@ -638,7 +639,8 @@ export async function renderToHTMLImpl(
const routerIsReady = !!( const routerIsReady = !!(
getServerSideProps || getServerSideProps ||
hasPageGetInitialProps || hasPageGetInitialProps ||
(!defaultAppGetInitialProps && !isSSG) (!defaultAppGetInitialProps && !isSSG) ||
isExperimentalCompile
) )
const router = new ServerRouter( const router = new ServerRouter(
pathname, pathname,
@ -1443,6 +1445,7 @@ export async function renderToHTMLImpl(
nextExport: nextExport === true ? true : undefined, // If this is a page exported by `next export` nextExport: nextExport === true ? true : undefined, // If this is a page exported by `next export`
autoExport: isAutoExport === true ? true : undefined, // If this is an auto exported page autoExport: isAutoExport === true ? true : undefined, // If this is an auto exported page
isFallback, isFallback,
isExperimentalCompile,
dynamicIds: dynamicIds:
dynamicImportsIds.size === 0 dynamicImportsIds.size === 0
? undefined ? undefined

View file

@ -830,6 +830,7 @@ export default class Router implements BaseRouter {
this.isReady = !!( this.isReady = !!(
self.__NEXT_DATA__.gssp || self.__NEXT_DATA__.gssp ||
self.__NEXT_DATA__.gip || self.__NEXT_DATA__.gip ||
self.__NEXT_DATA__.isExperimentalCompile ||
(self.__NEXT_DATA__.appGip && !self.__NEXT_DATA__.gsp) || (self.__NEXT_DATA__.appGip && !self.__NEXT_DATA__.gsp) ||
(!autoExportDynamic && (!autoExportDynamic &&
!self.location.search && !self.location.search &&

View file

@ -94,6 +94,7 @@ export type NEXT_DATA = {
nextExport?: boolean nextExport?: boolean
autoExport?: boolean autoExport?: boolean
isFallback?: boolean isFallback?: boolean
isExperimentalCompile?: boolean
dynamicIds?: (string | number)[] dynamicIds?: (string | number)[]
err?: Error & { err?: Error & {
statusCode?: number statusCode?: number

View file

@ -1482,11 +1482,7 @@ importers:
specifier: ^0.7.0 specifier: ^0.7.0
version: 0.7.3 version: 0.7.3
packages/next-plugin-storybook: packages/next-plugin-storybook: {}
dependencies:
next:
specifier: '*'
version: 13.5.3(@babel/core@7.18.0)(@opentelemetry/api@1.4.1)(react-dom@18.2.0)(react@18.2.0)(sass@1.54.0)
packages/next-polyfill-module: packages/next-polyfill-module:
devDependencies: devDependencies:
@ -6714,10 +6710,6 @@ packages:
resolution: {integrity: sha512-XQr74QaLeMiqhStEhLn1im9EOMnkypp7MZOwQhGzqp2Weu5eQJbpPxWxixxlYRKWPOmJjsk6qYfYH9kq43yc2w==} resolution: {integrity: sha512-XQr74QaLeMiqhStEhLn1im9EOMnkypp7MZOwQhGzqp2Weu5eQJbpPxWxixxlYRKWPOmJjsk6qYfYH9kq43yc2w==}
dev: true dev: true
/@next/env@13.5.3:
resolution: {integrity: sha512-X4te86vsbjsB7iO4usY9jLPtZ827Mbx+WcwNBGUOIuswuTAKQtzsuoxc/6KLxCMvogKG795MhrR1LDhYgDvasg==}
dev: false
/@next/react-refresh-utils@13.5.3(react-refresh@0.12.0)(webpack@5.86.0): /@next/react-refresh-utils@13.5.3(react-refresh@0.12.0)(webpack@5.86.0):
resolution: {integrity: sha512-Y4wsqtdX+/QZ6W19N3y/YnuxAt/a79l/zYmRc2mwEplP0rIv6W3MBo3ePFUXOMVfmVesnOhfnZanaGiynZcFOg==} resolution: {integrity: sha512-Y4wsqtdX+/QZ6W19N3y/YnuxAt/a79l/zYmRc2mwEplP0rIv6W3MBo3ePFUXOMVfmVesnOhfnZanaGiynZcFOg==}
peerDependencies: peerDependencies:
@ -6731,87 +6723,6 @@ packages:
webpack: 5.86.0(@swc/core@1.3.85) webpack: 5.86.0(@swc/core@1.3.85)
dev: true dev: true
/@next/swc-darwin-arm64@13.5.3:
resolution: {integrity: sha512-6hiYNJxJmyYvvKGrVThzo4nTcqvqUTA/JvKim7Auaj33NexDqSNwN5YrrQu+QhZJCIpv2tULSHt+lf+rUflLSw==}
engines: {node: '>= 10'}
cpu: [arm64]
os: [darwin]
requiresBuild: true
dev: false
optional: true
/@next/swc-darwin-x64@13.5.3:
resolution: {integrity: sha512-UpBKxu2ob9scbpJyEq/xPgpdrgBgN3aLYlxyGqlYX5/KnwpJpFuIHU2lx8upQQ7L+MEmz+fA1XSgesoK92ppwQ==}
engines: {node: '>= 10'}
cpu: [x64]
os: [darwin]
requiresBuild: true
dev: false
optional: true
/@next/swc-linux-arm64-gnu@13.5.3:
resolution: {integrity: sha512-5AzM7Yx1Ky+oLY6pHs7tjONTF22JirDPd5Jw/3/NazJ73uGB05NqhGhB4SbeCchg7SlVYVBeRMrMSZwJwq/xoA==}
engines: {node: '>= 10'}
cpu: [arm64]
os: [linux]
requiresBuild: true
dev: false
optional: true
/@next/swc-linux-arm64-musl@13.5.3:
resolution: {integrity: sha512-A/C1shbyUhj7wRtokmn73eBksjTM7fFQoY2v/0rTM5wehpkjQRLOXI8WJsag2uLhnZ4ii5OzR1rFPwoD9cvOgA==}
engines: {node: '>= 10'}
cpu: [arm64]
os: [linux]
requiresBuild: true
dev: false
optional: true
/@next/swc-linux-x64-gnu@13.5.3:
resolution: {integrity: sha512-FubPuw/Boz8tKkk+5eOuDHOpk36F80rbgxlx4+xty/U71e3wZZxVYHfZXmf0IRToBn1Crb8WvLM9OYj/Ur815g==}
engines: {node: '>= 10'}
cpu: [x64]
os: [linux]
requiresBuild: true
dev: false
optional: true
/@next/swc-linux-x64-musl@13.5.3:
resolution: {integrity: sha512-DPw8nFuM1uEpbX47tM3wiXIR0Qa+atSzs9Q3peY1urkhofx44o7E1svnq+a5Q0r8lAcssLrwiM+OyJJgV/oj7g==}
engines: {node: '>= 10'}
cpu: [x64]
os: [linux]
requiresBuild: true
dev: false
optional: true
/@next/swc-win32-arm64-msvc@13.5.3:
resolution: {integrity: sha512-zBPSP8cHL51Gub/YV8UUePW7AVGukp2D8JU93IHbVDu2qmhFAn9LWXiOOLKplZQKxnIPUkJTQAJDCWBWU4UWUA==}
engines: {node: '>= 10'}
cpu: [arm64]
os: [win32]
requiresBuild: true
dev: false
optional: true
/@next/swc-win32-ia32-msvc@13.5.3:
resolution: {integrity: sha512-ONcL/lYyGUj4W37D4I2I450SZtSenmFAvapkJQNIJhrPMhzDU/AdfLkW98NvH1D2+7FXwe7yclf3+B7v28uzBQ==}
engines: {node: '>= 10'}
cpu: [ia32]
os: [win32]
requiresBuild: true
dev: false
optional: true
/@next/swc-win32-x64-msvc@13.5.3:
resolution: {integrity: sha512-2Vz2tYWaLqJvLcWbbTlJ5k9AN6JD7a5CN2pAeIzpbecK8ZF/yobA39cXtv6e+Z8c5UJuVOmaTldEAIxvsIux/Q==}
engines: {node: '>= 10'}
cpu: [x64]
os: [win32]
requiresBuild: true
dev: false
optional: true
/@nicolo-ribaudo/chokidar-2@2.1.8-no-fsevents.3: /@nicolo-ribaudo/chokidar-2@2.1.8-no-fsevents.3:
resolution: {integrity: sha512-s88O1aVtXftvp5bCPB7WnmXc5IwOZZ7YPuwNPt+GtOOXpPvad1LfbmjYv+qII7zP6RU2QGnqve27dnLycEnyEQ==} resolution: {integrity: sha512-s88O1aVtXftvp5bCPB7WnmXc5IwOZZ7YPuwNPt+GtOOXpPvad1LfbmjYv+qII7zP6RU2QGnqve27dnLycEnyEQ==}
requiresBuild: true requiresBuild: true
@ -7291,6 +7202,7 @@ packages:
/@opentelemetry/api@1.4.1: /@opentelemetry/api@1.4.1:
resolution: {integrity: sha512-O2yRJce1GOc6PAy3QxFM4NzFiWzvScDC1/5ihYBL6BUEVdq0XMWN01sppE+H6bBXbaFYipjwFLEWLg5PaSOThA==} resolution: {integrity: sha512-O2yRJce1GOc6PAy3QxFM4NzFiWzvScDC1/5ihYBL6BUEVdq0XMWN01sppE+H6bBXbaFYipjwFLEWLg5PaSOThA==}
engines: {node: '>=8.0.0'} engines: {node: '>=8.0.0'}
dev: true
/@opentelemetry/core@1.15.2(@opentelemetry/api@1.4.1): /@opentelemetry/core@1.15.2(@opentelemetry/api@1.4.1):
resolution: {integrity: sha512-+gBv15ta96WqkHZaPpcDHiaz0utiiHZVfm2YOYSqFGrUaJpPkMoSuLBB58YFQGi6Rsb9EHos84X6X5+9JspmLw==} resolution: {integrity: sha512-+gBv15ta96WqkHZaPpcDHiaz0utiiHZVfm2YOYSqFGrUaJpPkMoSuLBB58YFQGi6Rsb9EHos84X6X5+9JspmLw==}
@ -19403,48 +19315,6 @@ packages:
resolution: {integrity: sha1-yobR/ogoFpsBICCOPchCS524NCw=} resolution: {integrity: sha1-yobR/ogoFpsBICCOPchCS524NCw=}
dev: true dev: true
/next@13.5.3(@babel/core@7.18.0)(@opentelemetry/api@1.4.1)(react-dom@18.2.0)(react@18.2.0)(sass@1.54.0):
resolution: {integrity: sha512-4Nt4HRLYDW/yRpJ/QR2t1v63UOMS55A38dnWv3UDOWGezuY0ZyFO1ABNbD7mulVzs9qVhgy2+ppjdsANpKP1mg==}
engines: {node: '>=16.14.0'}
hasBin: true
peerDependencies:
'@opentelemetry/api': ^1.1.0
react: ^18.2.0
react-dom: ^18.2.0
sass: ^1.3.0
peerDependenciesMeta:
'@opentelemetry/api':
optional: true
sass:
optional: true
dependencies:
'@next/env': 13.5.3
'@opentelemetry/api': 1.4.1
'@swc/helpers': 0.5.2
busboy: 1.6.0
caniuse-lite: 1.0.30001406
postcss: 8.4.14
react: 18.2.0
react-dom: 18.2.0(react@18.2.0)
sass: 1.54.0
styled-jsx: 5.1.1(@babel/core@7.18.0)(react@18.2.0)
watchpack: 2.4.0
zod: 3.21.4
optionalDependencies:
'@next/swc-darwin-arm64': 13.5.3
'@next/swc-darwin-x64': 13.5.3
'@next/swc-linux-arm64-gnu': 13.5.3
'@next/swc-linux-arm64-musl': 13.5.3
'@next/swc-linux-x64-gnu': 13.5.3
'@next/swc-linux-x64-musl': 13.5.3
'@next/swc-win32-arm64-msvc': 13.5.3
'@next/swc-win32-ia32-msvc': 13.5.3
'@next/swc-win32-x64-msvc': 13.5.3
transitivePeerDependencies:
- '@babel/core'
- babel-plugin-macros
dev: false
/nice-try@1.0.5: /nice-try@1.0.5:
resolution: {integrity: sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==} resolution: {integrity: sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==}
dev: true dev: true
@ -26882,10 +26752,6 @@ packages:
resolution: {integrity: sha512-N+d4UJSJbt/R3wqY7Coqs5pcV0aUj2j9IaQ3rNj9bVCLld8tTGKRa2USARjnvZJWVx1NDmQev8EknoczaOQDOA==} resolution: {integrity: sha512-N+d4UJSJbt/R3wqY7Coqs5pcV0aUj2j9IaQ3rNj9bVCLld8tTGKRa2USARjnvZJWVx1NDmQev8EknoczaOQDOA==}
dev: true dev: true
/zod@3.21.4:
resolution: {integrity: sha512-m46AKbrzKVzOzs/DZgVnG5H55N1sv1M8qZU3A8RIKbs3mrACDNeIOeilDymVb2HdmP8uwshOCF4uJ8uM9rCqJw==}
dev: false
/zwitch@1.0.5: /zwitch@1.0.5:
resolution: {integrity: sha512-V50KMwwzqJV0NpZIZFwfOD5/lyny3WlSzRiXgA0G7VUnRlqttta1L6UQIHzd6EuBY/cHGfwTIck7w1yH6Q5zUw==} resolution: {integrity: sha512-V50KMwwzqJV0NpZIZFwfOD5/lyny3WlSzRiXgA0G7VUnRlqttta1L6UQIHzd6EuBY/cHGfwTIck7w1yH6Q5zUw==}
dev: true dev: true

View file

@ -0,0 +1,9 @@
import 'e2e-utils'
process.env.NEXT_EXPERIMENTAL_COMPILE = '1'
if ((global as any).isNextStart) {
require('./index.test')
} else {
it('should skip', () => {})
}

View file

@ -7,14 +7,19 @@ createNextDescribe(
'app dir', 'app dir',
{ {
files: __dirname, files: __dirname,
buildCommand: process.env.NEXT_EXPERIMENTAL_COMPILE
? 'pnpm next experimental-compile'
: undefined,
}, },
({ next, isNextDev: isDev, isNextStart, isNextDeploy }) => { ({ next, isNextDev: isDev, isNextStart, isNextDeploy }) => {
if (isNextStart) { if (isNextStart) {
it('should have correct size in build output', async () => { if (!process.env.NEXT_EXPERIMENTAL_COMPILE) {
expect(next.cliOutput).toMatch( it('should have correct size in build output', async () => {
/\/dashboard\/another.*? [^0]{1,} [\w]{1,}B/ expect(next.cliOutput).toMatch(
) /\/dashboard\/another.*? [^0]{1,} [\w]{1,}B/
}) )
})
}
it('should have correct preferredRegion values in manifest', async () => { it('should have correct preferredRegion values in manifest', async () => {
const middlewareManifest = JSON.parse( const middlewareManifest = JSON.parse(