Skip to content

Commit a849bf4

Browse files
committed
feat(config): add validation for clientParamParsing configuration
- Add validation to ensure clientParamParsing requires clientSegmentCache - Rename assignDefaults to assignDefaultsAndValidate for clarity - Add JSDoc documentation for config validation function - Add explanatory comment for clientParamParsing build flag
1 parent 4fe4e86 commit a849bf4

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

packages/next/src/build/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,6 +1526,8 @@ export default async function build(
15261526
prefetchSegmentSuffix: RSC_SEGMENT_SUFFIX,
15271527
prefetchSegmentDirSuffix: RSC_SEGMENTS_DIR_SUFFIX,
15281528
clientParamParsing:
1529+
// NOTE: once this is the default for `clientSegmentCache`, this
1530+
// should exclusively be based on the `clientSegmentCache` flag.
15291531
config.experimental.clientParamParsing ?? false,
15301532
},
15311533
rewriteHeaders: {

packages/next/src/server/config.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,15 @@ function warnCustomizedOption(
221221
}
222222
}
223223

224-
function assignDefaults(
224+
/**
225+
* Assigns defaults to the user config and validates the config.
226+
*
227+
* @param dir - The directory of the project.
228+
* @param userConfig - The user config.
229+
* @param silent - Whether to suppress warnings.
230+
* @returns The complete config.
231+
*/
232+
function assignDefaultsAndValidate(
225233
dir: string,
226234
userConfig: NextConfig & { configFileName: string },
227235
silent: boolean
@@ -1147,6 +1155,18 @@ function assignDefaults(
11471155
result.experimental.ppr = true
11481156
}
11491157

1158+
// We require clientSegmentCache to be enabled if clientParamParsing is
1159+
// enabled. This is because clientParamParsing is only relevant when
1160+
// clientSegmentCache is enabled.
1161+
if (
1162+
result.experimental.clientParamParsing &&
1163+
!result.experimental.clientSegmentCache
1164+
) {
1165+
throw new Error(
1166+
`\`experimental.clientParamParsing\` can not be \`true\` when \`experimental.clientSegmentCache\` is \`false\`. Client param parsing is only relevant when client segment cache is enabled.`
1167+
)
1168+
}
1169+
11501170
return result as NextConfigComplete
11511171
}
11521172

@@ -1303,7 +1323,7 @@ export default async function loadConfig(
13031323
checkDeprecations(customConfig as NextConfig, configFileName, silent, dir)
13041324

13051325
const config = await applyModifyConfig(
1306-
assignDefaults(
1326+
assignDefaultsAndValidate(
13071327
dir,
13081328
{
13091329
configOrigin: 'server',
@@ -1542,7 +1562,7 @@ export default async function loadConfig(
15421562
phase,
15431563
})
15441564

1545-
const completeConfig = assignDefaults(
1565+
const completeConfig = assignDefaultsAndValidate(
15461566
dir,
15471567
{
15481568
configOrigin: relative(dir, path),
@@ -1600,7 +1620,7 @@ export default async function loadConfig(
16001620

16011621
// always call assignDefaults to ensure settings like
16021622
// reactRoot can be updated correctly even with no next.config.js
1603-
const completeConfig = assignDefaults(
1623+
const completeConfig = assignDefaultsAndValidate(
16041624
dir,
16051625
{ ...clonedDefaultConfig, configFileName },
16061626
silent

0 commit comments

Comments
 (0)