Skip to content

Commit

Permalink
Fix missing cache-control on SSR app route (#70265)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ijjk authored Sep 19, 2024
1 parent 89242ec commit 8f9c6a8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
5 changes: 1 addition & 4 deletions packages/next/src/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3119,10 +3119,7 @@ export default abstract class Server<
isRoutePPREnabled
) {
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
if (isPreviewMode) {
revalidate = 0
Expand Down
12 changes: 12 additions & 0 deletions test/e2e/app-dir/app/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
it('should provide query for getStaticProps page correctly', async () => {
const res = await next.fetch('/ssg?hello=world')
Expand Down
16 changes: 16 additions & 0 deletions test/e2e/app-dir/app/pages/ssr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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: {},
}
}

0 comments on commit 8f9c6a8

Please sign in to comment.