Unverified Commit 89816449 authored by Josh Story's avatar Josh Story Committed by GitHub

Keep compile-mode metadata outside configuration (#99491)

## Summary

Pass the build manifest's compile-mode marker separately to server
rendering, leaving the loaded configuration unchanged. This supports
immutable Next.js configuration for adapters without introducing another
mutable config representation.

Preserve the manifest override, including a false or absent marker, and
the existing config fallback when the manifest cannot be read.

## Verification

- `pnpm test-start-webpack
test/e2e/app-dir/app/experimental-compile.test.ts -t 'should provide
query for getStaticProps page correctly|should run generate command
correctly'` (2 passed)

<!-- NEXT_JS_LLM -->
parent f17e61cb
......@@ -221,6 +221,11 @@ export interface Options {
* Object containing the configuration next.config.js
*/
conf: NextConfig
/**
* Present when the build manifest was read, even if its marker is undefined.
* @internal
*/
compileMode?: { isExperimentalCompile: boolean | undefined }
/**
* Set to false when the server was created by Next.js
*/
......@@ -601,7 +606,9 @@ export default abstract class Server<
: undefined,
largePageDataBytes: this.nextConfig.experimental.largePageDataBytes,
isExperimentalCompile: this.nextConfig.experimental.isExperimentalCompile,
isExperimentalCompile: options.compileMode
? options.compileMode.isExperimentalCompile
: this.nextConfig.experimental.isExperimentalCompile,
cacheComponents: this.nextConfig.cacheComponents ?? false,
partialPrefetching: this.nextConfig.partialPrefetching,
validationLevel:
......
......@@ -43,7 +43,7 @@ const getServerImpl = async () => {
export type NextServerOptions = Omit<
ServerOptions | DevServerOptions,
// This is assigned in this server abstraction.
'conf'
'conf' | 'compileMode'
> &
Partial<Pick<ServerOptions | DevServerOptions, 'conf'>>
......@@ -365,8 +365,13 @@ export class NextServer implements NextWrapperServer {
)
).config
config.experimental.isExperimentalCompile =
serializedConfig.experimental.isExperimentalCompile
return {
config,
compileMode: {
isExperimentalCompile:
serializedConfig.experimental.isExperimentalCompile,
},
}
} catch (_) {
// if distDir is customized we don't know until we
// load the config so fallback to loading the config
......@@ -374,12 +379,13 @@ export class NextServer implements NextWrapperServer {
}
}
return config
return { config, compileMode: undefined }
}
private async getServer() {
if (!this.serverPromise) {
this.serverPromise = this[SYMBOL_LOAD_CONFIG]().then(async (conf) => {
this.serverPromise = this[SYMBOL_LOAD_CONFIG]().then(async (result) => {
const { config: conf, compileMode } = result
if (!this.options.dev) {
if (conf.output === 'standalone') {
if (!process.env.__NEXT_PRIVATE_STANDALONE_CONFIG) {
......@@ -397,6 +403,7 @@ export class NextServer implements NextWrapperServer {
this.server = await this.createServer({
...this.options,
conf,
compileMode,
})
if (this.preparedAssetPrefix) {
this.server.setAssetPrefix(this.preparedAssetPrefix)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment