Unverified Commit 818be9ae authored by Andrew Imm's avatar Andrew Imm Committed by GitHub

Warn when overriding Cache-Control header on `/_next/` routes (#88353)

Custom `Cache-Control` headers on `/_next/` routes can cause
hard-to-debug development behaviors. Normally the dev server sends
no-cache values to ensure that assets are always fresh. If a developer
sets the max-age or immutable flag,, the browser can cache resources
between requests, even if the source changes.

Adding a warning will at least make this problem easier to debug.
parent 7a2f4ad1
......@@ -725,6 +725,27 @@ export default async function loadCustomRoutes(
)
}
const cacheControlSources: string[] = []
for (const headerRoute of headers) {
if (!headerRoute.source.startsWith('/_next/')) {
continue
}
for (const header of headerRoute.headers) {
if (header.key.toLowerCase() === 'cache-control') {
cacheControlSources.push(headerRoute.source)
break
}
}
}
if (cacheControlSources.length > 0) {
console.warn(
bold(yellow(`Warning: `)) +
`Custom Cache-Control headers detected for the following routes:\n` +
cacheControlSources.map((source) => ` - ${source}`).join('\n') +
`\n\nSetting a custom Cache-Control header can break Next.js development behavior.`
)
}
if (config.experimental?.useSkewCookie && config.deploymentId) {
headers.unshift({
source: '/:path*',
......
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