Commit b503b8eb authored by JJ Kasper's avatar JJ Kasper

Fix missing cache-control on SSR app route (#70265)

This removes an inaccurate check that doesn't set a revalidate value if
revalidate is `undefined` which can be the case for SSR app route pages.
Also adds a regression test to ensure this doesn't break again.

Fixes: https://github.com/vercel/next.js/issues/70213
# Conflicts:
#	packages/next/src/server/base-server.ts
parent 6d7ced47
......@@ -2638,10 +2638,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
opts.experimental.ppr
) {
revalidate = 0
} else if (
typeof cacheEntry.revalidate !== 'undefined' &&
(!this.renderOpts.dev || (hasServerProps && !isNextDataRequest))
) {
} else if (!this.renderOpts.dev || (hasServerProps && !isNextDataRequest)) {
// If this is a preview mode request, we shouldn't cache it. We also don't
// cache 404 pages.
if (isPreviewMode || (is404Page && !isNextDataRequest)) {
......
......@@ -36,6 +36,18 @@ describe('app dir - basic', () => {
})
}
if (isNextStart) {
it('should have correct cache-control for SSR routes', async () => {
for (const path of ['/catch-all/first', '/ssr']) {
const res = await next.fetch(path)
expect(res.status).toBe(200)
expect(res.headers.get('Cache-Control')).toBe(
'private, no-cache, no-store, max-age=0, must-revalidate'
)
}
})
}
if (process.env.NEXT_EXPERIMENTAL_COMPILE) {
it('should provide query for getStaticProps page correctly', async () => {
const res = await next.fetch('/ssg?hello=world')
......
import { useRouter } from 'next/router'
export default function Page(props) {
return (
<>
<p>hello from ssr</p>
<p id="query">{JSON.stringify(useRouter().query)}</p>
</>
)
}
export function getServerSideProps() {
return {
props: {},
}
}
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