Unverified Commit 8f9c6a86 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

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
parent 89242ec1
...@@ -3119,10 +3119,7 @@ export default abstract class Server< ...@@ -3119,10 +3119,7 @@ export default abstract class Server<
isRoutePPREnabled isRoutePPREnabled
) { ) {
revalidate = 0 revalidate = 0
} else if ( } else if (!this.renderOpts.dev || (hasServerProps && !isNextDataRequest)) {
typeof cacheEntry.revalidate !== 'undefined' &&
(!this.renderOpts.dev || (hasServerProps && !isNextDataRequest))
) {
// If this is a preview mode request, we shouldn't cache it // If this is a preview mode request, we shouldn't cache it
if (isPreviewMode) { if (isPreviewMode) {
revalidate = 0 revalidate = 0
......
...@@ -20,6 +20,18 @@ describe('app dir - basic', () => { ...@@ -20,6 +20,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) { if (process.env.NEXT_EXPERIMENTAL_COMPILE) {
it('should provide query for getStaticProps page correctly', async () => { it('should provide query for getStaticProps page correctly', async () => {
const res = await next.fetch('/ssg?hello=world') 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