Unverified Commit 4494261b authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

Remove devCacheControlNoCache experimental option (hard-code no-cache) (#91503)

### What?

Removes the `experimental.devCacheControlNoCache` config option entirely
and hard-codes `no-cache, must-revalidate` as the dev server
`Cache-Control` header value.

Previously the option controlled whether the dev server responded with:
- `no-store, must-revalidate` (default, `false`)
- `no-cache, must-revalidate` (opt-in, `true`)

This PR first flips the default to `true`, then removes the option
altogether — making `no-cache, must-revalidate` unconditional in all dev
code paths.

### Why?

`no-cache` is strictly better than `no-store` for the dev server:
- `no-cache` allows the browser to revalidate (conditional
`If-None-Match`/`If-Modified-Since` requests), letting the server
respond with `304 Not Modified` when nothing changed → faster page loads
during development.
- `no-store` forces a full re-fetch every time, discarding valid cached
responses.

Since `no-cache` is the correct behavior for all dev users, the toggle
has no remaining value and can be removed to simplify the codebase.

### How?

**Two commits:**

1. `bcec825` — Flip the default from `false` → `true`; update
tests/fixtures/manifest to reflect the new default.

2. `e6e919f` — Remove the option entirely:
- Deleted `devCacheControlNoCache?: boolean` from `ExperimentalConfig`
interface, `config-schema.ts` Zod schema, `defaultConfig`,
`NextConfigRuntime`, and `getNextConfigRuntime()`.
- Replaced all four conditional ternaries in `base-server.ts`,
`router-server.ts`, `pages-handler.ts`, and `app-page.ts` with the
hard-coded string `'no-cache, must-revalidate'`.
- Deleted the `dev-cache-control-no-cache-disabled` test suite (was
testing the `false` path which no longer exists).
- Simplified the remaining `dev-cache-control-no-cache` test (removed
experimental framing).
   - Synced `rspack-dev-tests-manifest.json`.

---------
Co-authored-by: 's avatarTobias Koppers <sokra@users.noreply.github.com>
Co-authored-by: 's avatarClaude <noreply@anthropic.com>
Co-authored-by: 's avatarVercel <vercel[bot]@users.noreply.github.com>
parent 4050a5b0
......@@ -1389,12 +1389,7 @@ export async function handler(
// In dev, we should not cache pages for any reason.
if (routeModule.isDev) {
res.setHeader(
'Cache-Control',
nextConfig.experimental.devCacheControlNoCache
? 'no-cache, must-revalidate'
: 'no-store, must-revalidate'
)
res.setHeader('Cache-Control', 'no-cache, must-revalidate')
}
if (!cacheEntry) {
......
......@@ -1803,12 +1803,7 @@ export default abstract class Server<
// In dev, we should not cache pages for any reason.
if (this.dev) {
res.setHeader(
'Cache-Control',
this.nextConfig.experimental.devCacheControlNoCache
? 'no-cache, must-revalidate'
: 'no-store, must-revalidate'
)
res.setHeader('Cache-Control', 'no-cache, must-revalidate')
cacheControl = undefined
}
......
......@@ -404,7 +404,6 @@ export const experimentalSchema = {
hideLogsAfterAbort: z.boolean().optional(),
runtimeServerDeploymentId: z.boolean().optional(),
immutableAssetToken: z.string().optional(),
devCacheControlNoCache: z.boolean().optional(),
deferredEntries: z.array(z.string()).optional(),
onBeforeDeferredEntries: z.function().returns(z.promise(z.void())).optional(),
reportSystemEnvInlining: z.enum(['warn', 'error']).optional(),
......
......@@ -1039,18 +1039,6 @@ export interface ExperimentalConfig {
*/
immutableAssetToken?: string
/**
* Use 'no-cache' instead of 'no-store' in the Cache-Control header for development.
* This allows conditional requests to the server, which can help with development
* workflows that benefit from caching validation.
*
* When enabled, the Cache-Control header changes from 'no-store, must-revalidate'
* to 'no-cache, must-revalidate'.
*
* @default false
*/
devCacheControlNoCache?: boolean
/**
* An array of paths in app or pages directories that should wait to be processed
* until all other entries have been processed. This is useful for deferring
......@@ -1812,7 +1800,6 @@ export const defaultConfig = Object.freeze({
turbopackFileSystemCacheForBuild: false,
turbopackInferModuleSideEffects: true,
turbopackPluginRuntimeStrategy: 'childProcesses',
devCacheControlNoCache: false,
},
htmlLimitedBots: undefined,
bundlePagesRouterDependencies: false,
......@@ -1911,7 +1898,6 @@ export interface NextConfigRuntime {
| 'testProxy'
| 'runtimeServerDeploymentId'
| 'maxPostponedStateSize'
| 'devCacheControlNoCache'
| 'cachedNavigations'
| 'partialFallbacks'
| 'exposeTestingApiInProductionBuild'
......@@ -1982,7 +1968,6 @@ export function getNextConfigRuntime(
testProxy: ex.testProxy,
runtimeServerDeploymentId: ex.runtimeServerDeploymentId,
maxPostponedStateSize: ex.maxPostponedStateSize,
devCacheControlNoCache: ex.devCacheControlNoCache,
cachedNavigations: ex.cachedNavigations,
partialFallbacks: ex.partialFallbacks,
exposeTestingApiInProductionBuild: ex.exposeTestingApiInProductionBuild,
......
......@@ -507,12 +507,7 @@ export async function initialize(opts: {
matchedOutput.type === 'nextStaticFolder'
) {
if (opts.dev && !isNextFont(parsedUrl.pathname)) {
res.setHeader(
'Cache-Control',
config.experimental.devCacheControlNoCache
? 'no-cache, must-revalidate'
: 'no-store, must-revalidate'
)
res.setHeader('Cache-Control', 'no-cache, must-revalidate')
} else {
res.setHeader(
'Cache-Control',
......
......@@ -706,12 +706,7 @@ export const getHandler = ({
// In dev, we should not cache pages for any reason.
if (routeModule.isDev) {
res.setHeader(
'Cache-Control',
nextConfig.experimental.devCacheControlNoCache
? 'no-cache, must-revalidate'
: 'no-store, must-revalidate'
)
res.setHeader('Cache-Control', 'no-cache, must-revalidate')
}
// Draft mode should never be cached
......
export default function AppRoute() {
return <div>App Route</div>
}
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
import { nextTestSetup } from 'e2e-utils'
describe('experimental.devCacheControlNoCache disabled (default)', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('should use no-store for pages router by default', async () => {
const res = await next.fetch('/pages-route')
expect(res.headers.get('Cache-Control')).toBe('no-store, must-revalidate')
})
it('should use no-store for app router by default', async () => {
const res = await next.fetch('/app-route')
expect(res.headers.get('Cache-Control')).toBe('no-store, must-revalidate')
})
})
/** @type {import('next').NextConfig} */
module.exports = {}
export default function PagesRoute() {
return <div>Pages Route</div>
}
import { nextTestSetup } from 'e2e-utils'
describe('experimental.devCacheControlNoCache', () => {
describe('when enabled', () => {
const { next } = nextTestSetup({
files: __dirname,
})
describe('dev Cache-Control header', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('should use no-cache instead of no-store for pages router', async () => {
const res = await next.fetch('/pages-route')
expect(res.headers.get('Cache-Control')).toBe('no-cache, must-revalidate')
})
it('should use no-cache for pages router', async () => {
const res = await next.fetch('/pages-route')
expect(res.headers.get('Cache-Control')).toBe('no-cache, must-revalidate')
})
it('should use no-cache instead of no-store for app router', async () => {
const res = await next.fetch('/app-route')
expect(res.headers.get('Cache-Control')).toBe('no-cache, must-revalidate')
})
it('should use no-cache for app router', async () => {
const res = await next.fetch('/app-route')
expect(res.headers.get('Cache-Control')).toBe('no-cache, must-revalidate')
})
})
/** @type {import('next').NextConfig} */
module.exports = {
experimental: {
devCacheControlNoCache: true,
},
}
module.exports = {}
......@@ -396,7 +396,7 @@ describe('Client Navigation rendering', () => {
responses.forEach((res) => {
try {
expect(res.headers.get('Cache-Control')).toBe(
'no-store, must-revalidate'
'no-cache, must-revalidate'
)
} catch (err) {
err.message = res.url + ' ' + err.message
......
......@@ -15,14 +15,14 @@ describe('custom-cache-control', () => {
it('should have custom cache-control for app-ssg prerendered', async () => {
const res = await next.fetch('/app-ssg/first')
expect(res.headers.get('cache-control')).toBe(
isNextDev ? 'no-store, must-revalidate' : 's-maxage=30'
isNextDev ? 'no-cache, must-revalidate' : 's-maxage=30'
)
})
it('should have custom cache-control for app-ssg lazy', async () => {
const res = await next.fetch('/app-ssg/lazy')
expect(res.headers.get('cache-control')).toBe(
isNextDev ? 'no-store, must-revalidate' : 's-maxage=31'
isNextDev ? 'no-cache, must-revalidate' : 's-maxage=31'
)
})
;(process.env.__NEXT_CACHE_COMPONENTS ? it.skip : it)(
......@@ -32,7 +32,7 @@ describe('custom-cache-control', () => {
// eslint-disable-next-line jest/no-standalone-expect
expect(res.headers.get('cache-control')).toBe(
isNextDev
? 'no-store, must-revalidate'
? 'no-cache, must-revalidate'
: 's-maxage=120, stale-while-revalidate=31535880'
)
}
......@@ -41,28 +41,28 @@ describe('custom-cache-control', () => {
it('should have custom cache-control for app-ssr', async () => {
const res = await next.fetch('/app-ssr')
expect(res.headers.get('cache-control')).toBe(
isNextDev ? 'no-store, must-revalidate' : 's-maxage=32'
isNextDev ? 'no-cache, must-revalidate' : 's-maxage=32'
)
})
it('should have custom cache-control for auto static page', async () => {
const res = await next.fetch('/pages-auto-static')
expect(res.headers.get('cache-control')).toBe(
isNextDev ? 'no-store, must-revalidate' : 's-maxage=33'
isNextDev ? 'no-cache, must-revalidate' : 's-maxage=33'
)
})
it('should have custom cache-control for pages-ssg prerendered', async () => {
const res = await next.fetch('/pages-ssg/first')
expect(res.headers.get('cache-control')).toBe(
isNextDev ? 'no-store, must-revalidate' : 's-maxage=34'
isNextDev ? 'no-cache, must-revalidate' : 's-maxage=34'
)
})
it('should have custom cache-control for pages-ssg lazy', async () => {
const res = await next.fetch('/pages-ssg/lazy')
expect(res.headers.get('cache-control')).toBe(
isNextDev ? 'no-store, must-revalidate' : 's-maxage=35'
isNextDev ? 'no-cache, must-revalidate' : 's-maxage=35'
)
})
......@@ -70,7 +70,7 @@ describe('custom-cache-control', () => {
const res = await next.fetch('/pages-ssg/another')
expect(res.headers.get('cache-control')).toBe(
isNextDev
? 'no-store, must-revalidate'
? 'no-cache, must-revalidate'
: 's-maxage=120, stale-while-revalidate=31535880'
)
})
......@@ -78,7 +78,7 @@ describe('custom-cache-control', () => {
it('should have default cache-control for pages-ssr', async () => {
const res = await next.fetch('/pages-ssr')
expect(res.headers.get('cache-control')).toBe(
isNextDev ? 'no-store, must-revalidate' : 's-maxage=36'
isNextDev ? 'no-cache, must-revalidate' : 's-maxage=36'
)
})
})
......@@ -10,7 +10,9 @@ describe('fallback-prefetch', () => {
const browser = await next.browser('/', {
beforePageLoad: (page) => {
page.on('response', (response) => {
if (!response.ok()) {
// 304 Not Modified is a valid revalidation response (from no-cache),
// not a network error
if (!response.ok() && response.status() !== 304) {
hasNetworkError = true
}
})
......
......@@ -691,7 +691,7 @@ describe('app dir - metadata', () => {
expect(res.headers.get('content-type')).toBe('image/x-icon')
expect(res.headers.get('cache-control')).toBe(
isNextDev
? 'no-store, must-revalidate'
? 'no-cache, must-revalidate'
: 'public, max-age=0, must-revalidate'
)
})
......@@ -706,14 +706,14 @@ describe('app dir - metadata', () => {
expect(resAppleIcon.headers.get('content-type')).toBe('image/png')
expect(resAppleIcon.headers.get('cache-control')).toBe(
isNextDev
? 'no-store, must-revalidate'
? 'no-cache, must-revalidate'
: 'public, max-age=0, must-revalidate'
)
expect(resIcon.status).toBe(200)
expect(resIcon.headers.get('content-type')).toBe('image/png')
expect(resIcon.headers.get('cache-control')).toBe(
isNextDev
? 'no-store, must-revalidate'
? 'no-cache, must-revalidate'
: 'public, max-age=0, must-revalidate'
)
})
......
......@@ -192,7 +192,7 @@ describe.skip('ppr-full', () => {
if (isNextDeploy) {
expect(cacheControl).toEqual('public, max-age=0, must-revalidate')
} else if (isNextDev) {
expect(cacheControl).toEqual('no-store, must-revalidate')
expect(cacheControl).toEqual('no-cache, must-revalidate')
} else if (dynamic === false || dynamic === 'force-static') {
expect(cacheControl).toEqual(
revalidate === undefined
......
......@@ -91,7 +91,7 @@ describe('Prerender', () => {
}
function isCachingHeader(cacheControl) {
return !cacheControl || !/no-store/.test(cacheControl)
return !cacheControl || !/no-store|no-cache/.test(cacheControl)
}
const allowHeader = [
......
......@@ -1993,20 +1993,10 @@
"flakey": [],
"runtimeError": false
},
"test/development/dev-cache-control-no-cache-disabled/dev-cache-control-no-cache-disabled.test.ts": {
"passed": [
"experimental.devCacheControlNoCache disabled (default) should use no-store for app router by default",
"experimental.devCacheControlNoCache disabled (default) should use no-store for pages router by default"
],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/development/dev-cache-control-no-cache/dev-cache-control-no-cache.test.ts": {
"passed": [
"experimental.devCacheControlNoCache when enabled should use no-cache instead of no-store for app router",
"experimental.devCacheControlNoCache when enabled should use no-cache instead of no-store for pages router"
"dev Cache-Control header should use no-cache for app router",
"dev Cache-Control header should use no-cache for pages router"
],
"failed": [],
"pending": [],
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