Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
27 changes: 24 additions & 3 deletions packages/next/src/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1267,10 +1267,12 @@ export default async function loadConfig(
throw err
}

const userConfig = (await normalizeConfig(
// Clone a new userConfig each time to avoid mutating the original
const loadedConfig = (await normalizeConfig(
phase,
userConfigModule.default || userConfigModule
interopDefault(userConfigModule)
)) as NextConfig
const userConfig = cloneObject(loadedConfig) as NextConfig

if (!process.env.NEXT_MINIMAL) {
// We only validate the config against schema in non minimal mode
Expand Down Expand Up @@ -1388,7 +1390,7 @@ export default async function loadConfig(
userConfig.htmlLimitedBots = userConfig.htmlLimitedBots.source
}

onLoadUserConfig?.(userConfig)
onLoadUserConfig?.(Object.freeze(loadedConfig))
const completeConfig = assignDefaults(
dir,
{
Expand Down Expand Up @@ -1476,3 +1478,22 @@ export function getConfiguredExperimentalFeatures(
}
return configuredExperimentalFeatures
}

function cloneObject(obj: any): any {
Comment thread
huozhi marked this conversation as resolved.
if (obj === null || typeof obj !== 'object') {
return obj
}

if (Array.isArray(obj)) {
return obj.map(cloneObject)
}
const keys = Object.keys(obj)
if (keys.length === 0) {
Comment thread
huozhi marked this conversation as resolved.
return obj
}

return keys.reduce((acc, key) => {
;(acc as any)[key] = cloneObject(obj[key])
return acc
}, {})
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { nextTestSetup } from 'e2e-utils'

describe('app-dir - metadata-streaming-customized-rule', () => {
const { next } = nextTestSetup({
const { next, isNextDev } = nextTestSetup({
files: __dirname,
overrideFiles: {
'next.config.js': `
Expand Down Expand Up @@ -39,4 +39,12 @@ describe('app-dir - metadata-streaming-customized-rule', () => {
expect(await $('head title').length).toBe(0)
expect(await $('body title').length).toBe(1)
})

if (isNextDev) {
it('should not have schema issue', () => {
expect(next.cliOutput).not.toContain(
'Invalid next.config.js options detected'
)
})
}
})
6 changes: 0 additions & 6 deletions test/integration/config-experimental-warning/next.config.js

This file was deleted.