Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0e7e3a2

Browse filesBrowse files
piehmrstork
andauthored
fix: don't set permanent caching header when res.revalidate() was used (#2810)
* test: api route calling res.revalidate on path returning notFound: true is not cacheable * fix: don't set permanent caching header when res.revalidate() was used * test: adjust added test name, add some context, handle case of header not being set --------- Co-authored-by: Mateusz Bocian <mrstork@users.noreply.github.com>
1 parent f1b8509 commit 0e7e3a2
Copy full SHA for 0e7e3a2

File tree

Expand file treeCollapse file tree

2 files changed

+17
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+17
-1
lines changed

‎src/run/headers.ts

Copy file name to clipboardExpand all lines: src/run/headers.ts
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ export const setCacheControlHeaders = (
266266
['GET', 'HEAD'].includes(request.method) &&
267267
!headers.has('cdn-cache-control') &&
268268
!headers.has('netlify-cdn-cache-control') &&
269-
requestContext.usedFsReadForNonFallback
269+
requestContext.usedFsReadForNonFallback &&
270+
!requestContext.didPagesRouterOnDemandRevalidate
270271
) {
271272
// handle CDN Cache Control on static files
272273
headers.set('cache-control', 'public, max-age=0, must-revalidate')

‎tests/e2e/page-router.test.ts

Copy file name to clipboardExpand all lines: tests/e2e/page-router.test.ts
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,21 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
590590
'getStaticProps duration should not be longer than 10 seconds',
591591
).toBeLessThan(10_000)
592592
})
593+
594+
test('API route calling res.revalidate() on page returning notFound: true is not cacheable', async ({
595+
page,
596+
pageRouter,
597+
}) => {
598+
// note: known conditions for problematic case is
599+
// 1. API route needs to call res.revalidate()
600+
// 2. revalidated page's getStaticProps must return notFound: true
601+
const response = await page.goto(
602+
new URL('/api/revalidate?path=/static/not-found', pageRouter.url).href,
603+
)
604+
605+
expect(response?.status()).toEqual(200)
606+
expect(response?.headers()['netlify-cdn-cache-control'] ?? '').not.toMatch(/(s-maxage|max-age)/)
607+
})
593608
})
594609

595610
test.describe('Page Router with basePath and i18n', () => {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.