Skip to content

Commit b503b8e

Browse files
committed
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: #70213 # Conflicts: # packages/next/src/server/base-server.ts
1 parent 6d7ced4 commit b503b8e

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

packages/next/src/server/base-server.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2638,10 +2638,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
26382638
opts.experimental.ppr
26392639
) {
26402640
revalidate = 0
2641-
} else if (
2642-
typeof cacheEntry.revalidate !== 'undefined' &&
2643-
(!this.renderOpts.dev || (hasServerProps && !isNextDataRequest))
2644-
) {
2641+
} else if (!this.renderOpts.dev || (hasServerProps && !isNextDataRequest)) {
26452642
// If this is a preview mode request, we shouldn't cache it. We also don't
26462643
// cache 404 pages.
26472644
if (isPreviewMode || (is404Page && !isNextDataRequest)) {

test/e2e/app-dir/app/index.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ describe('app dir - basic', () => {
3636
})
3737
}
3838

39+
if (isNextStart) {
40+
it('should have correct cache-control for SSR routes', async () => {
41+
for (const path of ['/catch-all/first', '/ssr']) {
42+
const res = await next.fetch(path)
43+
expect(res.status).toBe(200)
44+
expect(res.headers.get('Cache-Control')).toBe(
45+
'private, no-cache, no-store, max-age=0, must-revalidate'
46+
)
47+
}
48+
})
49+
}
50+
3951
if (process.env.NEXT_EXPERIMENTAL_COMPILE) {
4052
it('should provide query for getStaticProps page correctly', async () => {
4153
const res = await next.fetch('/ssg?hello=world')

test/e2e/app-dir/app/pages/ssr.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { useRouter } from 'next/router'
2+
3+
export default function Page(props) {
4+
return (
5+
<>
6+
<p>hello from ssr</p>
7+
<p id="query">{JSON.stringify(useRouter().query)}</p>
8+
</>
9+
)
10+
}
11+
12+
export function getServerSideProps() {
13+
return {
14+
props: {},
15+
}
16+
}

0 commit comments

Comments
 (0)