Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
2557fba3
Commit
2557fba3
authored
Jun 17, 2025
by
Jiachi Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[fix] clone the config module to avoid mutation (#80573)
parent
616f6fa0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
10 deletions
+34
-10
config.ts
packages/next/src/server/config.ts
+25
-3
metadata-streaming-customized-rule.test.ts
...data-streaming/metadata-streaming-customized-rule.test.ts
+9
-1
next.config.js
test/integration/config-experimental-warning/next.config.js
+0
-6
No files found.
packages/next/src/server/config.ts
View file @
2557fba3
...
@@ -30,6 +30,7 @@ import { normalizeZodErrors } from '../shared/lib/zod'
...
@@ -30,6 +30,7 @@ import { normalizeZodErrors } from '../shared/lib/zod'
import
{
HTML_LIMITED_BOT_UA_RE_STRING
}
from
'../shared/lib/router/utils/is-bot'
import
{
HTML_LIMITED_BOT_UA_RE_STRING
}
from
'../shared/lib/router/utils/is-bot'
import
{
findDir
}
from
'../lib/find-pages-dir'
import
{
findDir
}
from
'../lib/find-pages-dir'
import
{
CanaryOnlyError
,
isStableBuild
}
from
'../shared/lib/canary-only'
import
{
CanaryOnlyError
,
isStableBuild
}
from
'../shared/lib/canary-only'
import
{
interopDefault
}
from
'../lib/interop-default'
export
{
normalizeConfig
}
from
'./config-shared'
export
{
normalizeConfig
}
from
'./config-shared'
export
type
{
DomainLocale
,
NextConfig
}
from
'./config-shared'
export
type
{
DomainLocale
,
NextConfig
}
from
'./config-shared'
...
@@ -1192,10 +1193,12 @@ export default async function loadConfig(
...
@@ -1192,10 +1193,12 @@ export default async function loadConfig(
throw
err
throw
err
}
}
const
userConfig
=
(
await
normalizeConfig
(
// Clone a new userConfig each time to avoid mutating the original
const
loadedConfig
=
(
await
normalizeConfig
(
phase
,
phase
,
userConfigModule
.
default
||
userConfigModule
interopDefault
(
userConfigModule
)
))
as
NextConfig
))
as
NextConfig
const
userConfig
=
cloneObject
(
loadedConfig
)
as
NextConfig
if
(
!
process
.
env
.
NEXT_MINIMAL
)
{
if
(
!
process
.
env
.
NEXT_MINIMAL
)
{
// We only validate the config against schema in non minimal mode
// We only validate the config against schema in non minimal mode
...
@@ -1312,7 +1315,7 @@ export default async function loadConfig(
...
@@ -1312,7 +1315,7 @@ export default async function loadConfig(
userConfig
.
htmlLimitedBots
=
userConfig
.
htmlLimitedBots
.
source
userConfig
.
htmlLimitedBots
=
userConfig
.
htmlLimitedBots
.
source
}
}
onLoadUserConfig
?.(
userConfig
)
onLoadUserConfig
?.(
Object
.
freeze
(
loadedConfig
)
)
const
completeConfig
=
assignDefaults
(
const
completeConfig
=
assignDefaults
(
dir
,
dir
,
{
{
...
@@ -1401,3 +1404,22 @@ export function getConfiguredExperimentalFeatures(
...
@@ -1401,3 +1404,22 @@ export function getConfiguredExperimentalFeatures(
}
}
return
configuredExperimentalFeatures
return
configuredExperimentalFeatures
}
}
function
cloneObject
(
obj
:
any
):
any
{
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
)
{
return
obj
}
return
keys
.
reduce
((
acc
,
key
)
=>
{
;(
acc
as
any
)[
key
]
=
cloneObject
(
obj
[
key
])
return
acc
},
{})
}
test/e2e/app-dir/metadata-streaming/metadata-streaming-customized-rule.test.ts
View file @
2557fba3
import
{
nextTestSetup
}
from
'e2e-utils'
import
{
nextTestSetup
}
from
'e2e-utils'
describe
(
'app-dir - metadata-streaming-customized-rule'
,
()
=>
{
describe
(
'app-dir - metadata-streaming-customized-rule'
,
()
=>
{
const
{
next
}
=
nextTestSetup
({
const
{
next
,
isNextDev
}
=
nextTestSetup
({
files
:
__dirname
,
files
:
__dirname
,
overrideFiles
:
{
overrideFiles
:
{
'next.config.js'
:
`
'next.config.js'
:
`
...
@@ -39,4 +39,12 @@ describe('app-dir - metadata-streaming-customized-rule', () => {
...
@@ -39,4 +39,12 @@ describe('app-dir - metadata-streaming-customized-rule', () => {
expect
(
await
$
(
'head title'
).
length
).
toBe
(
0
)
expect
(
await
$
(
'head title'
).
length
).
toBe
(
0
)
expect
(
await
$
(
'body title'
).
length
).
toBe
(
1
)
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'
)
})
}
})
})
test/integration/config-experimental-warning/next.config.js
deleted
100644 → 0
View file @
616f6fa0
module
.
exports
=
{
experimental
:
{
staticGenerationRetryCount
:
2
,
staticGenerationMaxConcurrency
:
4
,
},
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment