Unverified Commit efa1ad49 authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

auto-enable clientParamParsing and clientSegmentCache w/ cacheComponents (#84250)

When you try `experimental.cacheComponents`, we should auto-enable the
supporting flags (`clientSegmentCache`, `clientParamParsing`), just like
we were doing with PPR to avoid the need to think about all the
different flags needed to get the best cache components testing
experience. Like before, these flags can be explicitly disabled for any
reason.
parent a432e06d
...@@ -1690,59 +1690,68 @@ function enforceExperimentalFeatures( ...@@ -1690,59 +1690,68 @@ function enforceExperimentalFeatures(
} }
} }
// TODO: Remove this once we've made Client Segment Cache the default. // TODO: Remove this once we've made Cache Components the default.
if ( if (
process.env.__NEXT_EXPERIMENTAL_PPR === 'true' && process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true' &&
// We do respect an explicit value in the user config. // We do respect an explicit value in the user config.
(config.experimental.clientSegmentCache === undefined || (config.experimental.cacheComponents === undefined ||
(isDefaultConfig && !config.experimental.clientSegmentCache)) (isDefaultConfig && !config.experimental.cacheComponents))
) { ) {
config.experimental.clientSegmentCache = true config.experimental.cacheComponents = true
if (configuredExperimentalFeatures) { if (configuredExperimentalFeatures) {
addConfiguredExperimentalFeature( addConfiguredExperimentalFeature(
configuredExperimentalFeatures, configuredExperimentalFeatures,
'clientSegmentCache', 'cacheComponents',
true, true,
'enabled by `__NEXT_EXPERIMENTAL_PPR`' 'enabled by `__NEXT_EXPERIMENTAL_CACHE_COMPONENTS`'
) )
} }
} }
// TODO: Remove this once we've made Client Param Parsing the default. const enabledByPprEnv = process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
const enabledByCacheComponents = config.experimental.cacheComponents === true
// TODO: Remove this once we've made Client Segment Cache the default.
if ( if (
process.env.__NEXT_EXPERIMENTAL_PPR === 'true' && (enabledByPprEnv || enabledByCacheComponents) &&
// We do respect an explicit value in the user config. // We do respect an explicit value in the user config.
(config.experimental.clientParamParsing === undefined || (config.experimental.clientSegmentCache === undefined ||
(isDefaultConfig && !config.experimental.clientParamParsing)) (isDefaultConfig && !config.experimental.clientSegmentCache))
) { ) {
config.experimental.clientParamParsing = true config.experimental.clientSegmentCache = true
const reason = enabledByCacheComponents
? 'enabled by `experimental.cacheComponents`'
: 'enabled by `__NEXT_EXPERIMENTAL_PPR`'
if (configuredExperimentalFeatures) { if (configuredExperimentalFeatures) {
addConfiguredExperimentalFeature( addConfiguredExperimentalFeature(
configuredExperimentalFeatures, configuredExperimentalFeatures,
'clientParamParsing', 'clientSegmentCache',
true, true,
'enabled by `__NEXT_EXPERIMENTAL_PPR`' reason
) )
} }
} }
// TODO: Remove this once we've made Cache Components the default. // TODO: Remove this once we've made Client Param Parsing the default.
if ( if (
process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true' && (enabledByPprEnv || enabledByCacheComponents) &&
// We do respect an explicit value in the user config. // We do respect an explicit value in the user config.
(config.experimental.cacheComponents === undefined || (config.experimental.clientParamParsing === undefined ||
(isDefaultConfig && !config.experimental.cacheComponents)) (isDefaultConfig && !config.experimental.clientParamParsing))
) { ) {
config.experimental.cacheComponents = true config.experimental.clientParamParsing = true
const reason = enabledByCacheComponents
? 'enabled by `experimental.cacheComponents`'
: 'enabled by `__NEXT_EXPERIMENTAL_PPR`'
if (configuredExperimentalFeatures) { if (configuredExperimentalFeatures) {
addConfiguredExperimentalFeature( addConfiguredExperimentalFeature(
configuredExperimentalFeatures, configuredExperimentalFeatures,
'cacheComponents', 'clientParamParsing',
true, true,
'enabled by `__NEXT_EXPERIMENTAL_CACHE_COMPONENTS`' reason
) )
} }
} }
......
...@@ -93,7 +93,11 @@ describe('segment cache (basic tests)', () => { ...@@ -93,7 +93,11 @@ describe('segment cache (basic tests)', () => {
) )
}) })
it('navigate to page with lazily-generated (not at build time) static param', async () => { // TODO(client-param-parsing): With `clientParamParsing` enabled, this test is outdated, because
// we no longer put the param values in the prefetched RSC response. You'd have to opt into runtime
// prefetching for this test to pass until we ship the optimization that would mark this as fully static
// if you don't reference any dynamic params in the server components.
it.skip('navigate to page with lazily-generated (not at build time) static param', async () => {
let act: ReturnType<typeof createRouterAct> let act: ReturnType<typeof createRouterAct>
const browser = await next.browser('/lazily-generated-params', { const browser = await next.browser('/lazily-generated-params', {
beforePageLoad(page) { beforePageLoad(page) {
......
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