-
Notifications
You must be signed in to change notification settings - Fork 329
fix(pages-router): pass revalidateReason to gssp/getStaticProps context #1573
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -583,6 +583,19 @@ export function createSSRHandler( | |
| gsspExtraHeaders[key] = String(val); | ||
| } | ||
| } | ||
|
|
||
| // Default Cache-Control for getServerSideProps responses, matching | ||
| // Next.js's pages-handler.ts (revalidate: 0 → getCacheControlHeader). | ||
| // Skip when gSSP already set one via res.setHeader (case-insensitive) | ||
| // or when ISR is layered on top below — that branch overwrites this | ||
| // default with the ISR cache-control. Fixes #1461. | ||
| const hasUserCacheControl = Object.keys(gsspExtraHeaders).some( | ||
| (k) => k.toLowerCase() === "cache-control", | ||
| ); | ||
| if (!hasUserCacheControl) { | ||
| gsspExtraHeaders["Cache-Control"] = | ||
| "private, no-cache, no-store, max-age=0, must-revalidate"; | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This default Cache-Control fix is correct for dev, but the production path ( The fix should also go in Also, this is an unrelated fix (referencing #1461) bundled into a PR whose title and description only mention |
||
| } | ||
| // Collect font preloads early so ISR cached responses can include | ||
| // the Link header (font preloads are module-level state that persists | ||
|
|
@@ -673,6 +686,9 @@ export function createSSRHandler( | |
| locale: locale ?? currentDefaultLocale, | ||
| locales: i18nConfig?.locales, | ||
| defaultLocale: currentDefaultLocale, | ||
| // Stale-while-revalidate background regeneration — mirrors | ||
| // Next.js `render.tsx`'s `revalidateReason` resolution. | ||
| revalidateReason: "stale", | ||
| }); | ||
| if (freshResult && "props" in freshResult) { | ||
| const revalidate = | ||
|
|
@@ -796,12 +812,17 @@ export function createSSRHandler( | |
| return; | ||
| } | ||
|
|
||
| // Cache miss — call getStaticProps normally | ||
| // Cache miss — call getStaticProps normally. | ||
| // Dev has no build-time prerender phase, so every dev hit is | ||
| // treated as a stale-while-revalidate refresh — mirrors Next.js | ||
| // `render.tsx` (`isBuildTimeSSG ? "build" : "stale"`). | ||
| // See `.nextjs-ref/test/e2e/revalidate-reason/revalidate-reason.test.ts`. | ||
| const context = { | ||
| params: userFacingParams, | ||
| locale: locale ?? currentDefaultLocale, | ||
| locales: i18nConfig?.locales, | ||
| defaultLocale: currentDefaultLocale, | ||
| revalidateReason: "stale" as const, | ||
| }; | ||
| const result = await pageModule.getStaticProps(context); | ||
| if (result && "props" in result) { | ||
|
|
||
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.
isOnDemandRevalidateis not passed here, so the"on-demand"branch inresolvePagesPageDatais currently unreachable. That's fine as forward-looking plumbing, but consider adding a brief comment noting that on-demand revalidation (res.revalidate()) is not yet wired up — it will save someone from wondering why it's never set.