mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
4494261bd7
### 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: Tobias Koppers <[email protected]> Co-authored-by: Claude <[email protected]> Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
85 lines
2.8 KiB
TypeScript
85 lines
2.8 KiB
TypeScript
import { nextTestSetup } from 'e2e-utils'
|
|
|
|
describe('custom-cache-control', () => {
|
|
const { next, isNextDev, isNextDeploy } = nextTestSetup({
|
|
files: __dirname,
|
|
})
|
|
|
|
if (isNextDeploy) {
|
|
// customizing these headers won't apply on environments
|
|
// where headers are applied outside of the Next.js server
|
|
it('should skip for deploy', () => {})
|
|
return
|
|
}
|
|
|
|
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-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-cache, must-revalidate' : 's-maxage=31'
|
|
)
|
|
})
|
|
;(process.env.__NEXT_CACHE_COMPONENTS ? it.skip : it)(
|
|
'should have default cache-control for app-ssg another',
|
|
async () => {
|
|
const res = await next.fetch('/app-ssg/another')
|
|
// eslint-disable-next-line jest/no-standalone-expect
|
|
expect(res.headers.get('cache-control')).toBe(
|
|
isNextDev
|
|
? 'no-cache, must-revalidate'
|
|
: 's-maxage=120, stale-while-revalidate=31535880'
|
|
)
|
|
}
|
|
)
|
|
|
|
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-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-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-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-cache, must-revalidate' : 's-maxage=35'
|
|
)
|
|
})
|
|
|
|
it('should have default cache-control for pages-ssg another', async () => {
|
|
const res = await next.fetch('/pages-ssg/another')
|
|
expect(res.headers.get('cache-control')).toBe(
|
|
isNextDev
|
|
? 'no-cache, must-revalidate'
|
|
: 's-maxage=120, stale-while-revalidate=31535880'
|
|
)
|
|
})
|
|
|
|
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-cache, must-revalidate' : 's-maxage=36'
|
|
)
|
|
})
|
|
})
|