Unverified Commit ccd47cfe authored by Hendrik Liebau's avatar Hendrik Liebau Committed by GitHub

Warn that `experimental.useCache` is deprecated (#96448)

parent 893121b8
...@@ -1462,5 +1462,6 @@ ...@@ -1462,5 +1462,6 @@
"1461": "Expected segment cache to have data for stage '%s'", "1461": "Expected segment cache to have data for stage '%s'",
"1462": "Unexpected chunk emitted in Before stage", "1462": "Unexpected chunk emitted in Before stage",
"1463": "\\`experimental.turbopackGenerateComponentChunks\\` has been moved to \\`experimental.turbopackChunking.generateComponentChunks\\`. Please update your next.config.js file accordingly.", "1463": "\\`experimental.turbopackGenerateComponentChunks\\` has been moved to \\`experimental.turbopackChunking.generateComponentChunks\\`. Please update your next.config.js file accordingly.",
"1464": "\\`experimental.turbopackChunkingHeuristics\\` has been renamed to \\`experimental.turbopackChunking\\`. Please update your next.config.js file accordingly." "1464": "\\`experimental.turbopackChunkingHeuristics\\` has been renamed to \\`experimental.turbopackChunking\\`. Please update your next.config.js file accordingly.",
"1465": "\\`experimental.useCache\\` cannot be disabled when \\`cacheComponents\\` is enabled, because Cache Components relies on the \\`\"use cache\"\\` directive. Please remove it from %s."
} }
...@@ -1605,6 +1605,32 @@ function assignDefaultsAndValidate( ...@@ -1605,6 +1605,32 @@ function assignDefaultsAndValidate(
result.experimental.ppr = true result.experimental.ppr = true
} }
// `experimental.useCache` is deprecated in favor of the top-level
// `cacheComponents` option. A defined value means the user set the option
// explicitly, because it's only backfilled from `cacheComponents` below.
if (result.experimental.useCache !== undefined) {
// Disabling the directive that Cache Components is built around leaves the
// app in a state where every `"use cache"` fails to compile with an error
// that asks for the already-enabled `cacheComponents` option.
if (!result.experimental.useCache && result.cacheComponents) {
throw new Error(
`\`experimental.useCache\` cannot be disabled when \`cacheComponents\` is enabled, because Cache Components relies on the \`"use cache"\` directive. Please remove it from ${configFileName}.`
)
}
if (!silent) {
if (result.cacheComponents) {
Log.warnOnce(
`\`experimental.useCache\` is no longer needed, because \`cacheComponents\` already enables the \`"use cache"\` directive. You can remove it from ${configFileName}.`
)
} else {
Log.warnOnce(
`\`experimental.useCache\` is deprecated. Please use the top-level \`cacheComponents\` option instead in ${configFileName}.`
)
}
}
}
// "use cache" was originally implicitly enabled with the cacheComponents flag, so // "use cache" was originally implicitly enabled with the cacheComponents flag, so
// we transfer the value for cacheComponents to the explicit useCache flag to ensure // we transfer the value for cacheComponents to the explicit useCache flag to ensure
// backwards compatibility. // backwards compatibility.
......
...@@ -44,6 +44,20 @@ describe('use-cache', () => { ...@@ -44,6 +44,20 @@ describe('use-cache', () => {
) )
}) })
it('should warn that the `experimental.useCache` config option is deprecated', async () => {
// The fixture enables `experimental.useCache`, so the warning is emitted
// when the server loads the config, shortly after it reports readiness.
// Which of the two variants is printed depends on whether `cacheComponents`
// already enables the directive.
await retry(async () => {
expect(stripAnsi(next.cliOutput)).toContain(
withCacheComponents
? '`experimental.useCache` is no longer needed, because `cacheComponents` already enables the `"use cache"` directive. You can remove it from next.config.js.'
: '`experimental.useCache` is deprecated. Please use the top-level `cacheComponents` option instead in next.config.js.'
)
})
})
it('should cache results', async () => { it('should cache results', async () => {
const browser = await next.browser(`/?n=1`) const browser = await next.browser(`/?n=1`)
expect(await browser.waitForElementByCss('#x').text()).toBe('1') expect(await browser.waitForElementByCss('#x').text()).toBe('1')
......
...@@ -275,4 +275,45 @@ describe('config', () => { ...@@ -275,4 +275,45 @@ describe('config', () => {
expect(config.partialPrefetching).toBe(true) expect(config.partialPrefetching).toBe(true)
}) })
}) })
describe('experimental.useCache config', () => {
it('Should throw when `useCache` is disabled while `cacheComponents` is enabled', async () => {
await expect(async () => {
await loadConfig(PHASE_DEVELOPMENT_SERVER, '<rootDir>-uc-conflict', {
customConfig: {
cacheComponents: true,
experimental: { useCache: false },
},
})
}).rejects.toThrow(
/`experimental.useCache` cannot be disabled when `cacheComponents` is enabled/
)
})
it('Should accept `useCache: false` when `cacheComponents` is not enabled', async () => {
const config = await loadConfig(
PHASE_DEVELOPMENT_SERVER,
'<rootDir>-uc-off',
{
customConfig: {
experimental: { useCache: false },
},
}
)
expect(config.experimental.useCache).toBe(false)
})
it('Should backfill `useCache` from `cacheComponents` when it is not set', async () => {
const config = await loadConfig(
PHASE_DEVELOPMENT_SERVER,
'<rootDir>-uc-backfill',
{
customConfig: {
cacheComponents: true,
},
}
)
expect(config.experimental.useCache).toBe(true)
})
})
}) })
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