File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1268,12 +1268,9 @@ export default async function loadConfig(
12681268 }
12691269
12701270 // Clone a new userConfig each time to avoid mutating the original
1271- const userConfig = {
1272- ...( await normalizeConfig (
1273- phase ,
1274- userConfigModule . default || userConfigModule
1275- ) ) ,
1276- } as NextConfig
1271+ const userConfig = cloneObject (
1272+ await normalizeConfig ( phase , userConfigModule . default || userConfigModule )
1273+ ) as NextConfig
12771274
12781275 if ( ! process . env . NEXT_MINIMAL ) {
12791276 // We only validate the config against schema in non minimal mode
@@ -1479,3 +1476,22 @@ export function getConfiguredExperimentalFeatures(
14791476 }
14801477 return configuredExperimentalFeatures
14811478}
1479+
1480+ function cloneObject ( obj : any ) : any {
1481+ if ( obj === null || typeof obj !== 'object' ) {
1482+ return obj
1483+ }
1484+
1485+ if ( Array . isArray ( obj ) ) {
1486+ return obj . map ( cloneObject )
1487+ }
1488+ const keys = Object . keys ( obj )
1489+ if ( keys . length === 0 ) {
1490+ return obj
1491+ }
1492+
1493+ return keys . reduce ( ( acc , key ) => {
1494+ ; ( acc as any ) [ key ] = cloneObject ( obj [ key ] )
1495+ return acc
1496+ } , { } )
1497+ }
You can’t perform that action at this time.
0 commit comments