-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: dynamic not-prerendered routes revalidate tracking #2771
Conversation
📊 Package size report 0.02%↑
Unchanged files
🤖 This report was automatically generated by pkg-size-action |
c9ba1e0
to
eb76546
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Go to go, assuming my assumption was correct in the comment above
@@ -413,12 +413,12 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => { | |||
expect(date1.localeCompare(beforeFirstFetch)).toBeGreaterThan(0) | |||
|
|||
// allow page to get stale | |||
await page.waitForTimeout(60_000) | |||
await page.waitForTimeout(61_000) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yes, I got tripped up by this too 😄
@@ -355,22 +374,25 @@ export class NetlifyCacheHandler implements CacheHandlerForMultipleVersions { | |||
if (isCachedRouteValue(data)) { | |||
return { | |||
...data, | |||
revalidate: context.revalidate, | |||
revalidate: context.revalidate ?? context.cacheControl?.revalidate, | |||
cacheControl: context.cacheControl, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm assuming we don't have to do this at build time too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still record initialRevalidateSeconds
from prerender-manifest.json
under revalidate
revalidate: initialRevalidateSeconds, |
Which is enough for how we read this value later for own needs (like figuring out initial cdn max age in some cases - like recently merged 404 caching fixes or preventing double SWR ) and Next.js also uses prerender-manifest.json
directly for anything that was prerendered ( https://github.com/vercel/next.js/blob/7e5e69dd2592e2b8d165d15b267ba3491f7d8174/packages/next/src/server/lib/incremental-cache/shared-cache-controls.ts#L36-L67 ), so we don't have to actually do the same at build time - otherwise we would also need to adjust our own code in places we rely on revalidate
field.
That is possibly something to think about, because cacheControl
field does contain expire
together revalidate
, so this would allow exact stale-while-revalidate=
value for cases that use
opennextjs-netlify/src/run/headers.ts
Lines 201 to 212 in 3301077
function setCacheControlFromRequestContext( | |
headers: Headers, | |
revalidate: NetlifyCachedRouteValue['revalidate'], | |
) { | |
const cdnCacheControl = | |
// if we are serving already stale response, instruct edge to not attempt to cache that response | |
headers.get('x-nextjs-cache') === 'STALE' | |
? 'public, max-age=0, must-revalidate, durable' | |
: `s-maxage=${revalidate || 31536000}, stale-while-revalidate=31536000, durable` | |
headers.set('netlify-cdn-cache-control', cdnCacheControl) | |
} |
So technically it might not be correct not to store it, but it probably be better for some follow up as amount it's already here is addressing substantial problem (with those next versions we never cache not-prerendered dynamic pages on cdn now)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I'll go ahead and merge this
Description
Adjustment to
revalidate
tracking after vercel/next.js#76207Tests
No new tests - we already have tests that were failing with latest/canary versions and this change make them pass again
Some unrelated test fixes: