ISSUE DESCRIPTION Pages Router: gssp/getStaticProps responses missing default and…
- User
ISSUE DESCRIPTION
Pages Router: gssp/getStaticProps responses missing default and user-set
Cache-ControlheaderThis issue was created by an agent analysing CI failures from the Next.js Deploy Suite (vinext
mainvs Next.jsv16.2.6, 2026-05-22).Problem
Pages Router gssp responses lack
Cache-Controlheaders. Tests expect the defaultprivate, no-cache, no-store, max-age=0, must-revalidatefor gssp pages and custom values set viares.setHeader('Cache-Control', ...), but vinext returnsnull. The default header is not applied and usersetHeadercalls are dropped.Expected: "private, no-cache, no-store, max-age=0, must-revalidate" Received: nullEstimated Impact
~2 test failures across the deploy suite.
Affected Test Suites
test/e2e/getserversideprops/test/index.test.ts(2 failures)
Recommendation
-
Reproduce first in vinext's own test suite. Add a Pages Router gssp page and assert the response carries the default
Cache-Controlheader; add a second page that overrides it viares.setHeaderand assert the override sticks. -
Emit the default gssp Cache-Control. When serving a gssp response in deploy mode, set
Cache-Control: private, no-cache, no-store, max-age=0, must-revalidateunless the user set it explicitly. -
Preserve
res.setHeaderoverrides. Make sure headers set during gssp dispatch are forwarded to the final HTTP response.
Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusor commands. However you don't need to use or before submitting your changes. In fact, only submits currently unstaged changes because it uses to get the changes that need to be submitted. Assistant
Let me explore the repository structure to understand the codebase.
Assistant
Let me analyze the issue. The
applyGsspHeadersfunction applies gssp headers to the response headers. Then the code sets Cache-Control conditionally:- If
scriptNonceis set →no-store, must-revalidate - Else if
isrRevalidateSeconds→ revalidate cache control - Otherwise → no Cache-Control is set
The issue is that for gssp pages, the default Cache-Control should be
private, no-cache, no-store, max-age=0, must-revalidateunless the user set it explicitly viares.setHeader('Cache-Control', ...).Currently the logic doesn't set a default Cache-Control for gssp pages. Also, the
applyGsspHeadersis called first, then the code overwrites Cache-Control if scriptNonce or isrRevalidateSeconds are set. But if user set Cache-Control via gsspRes, it would be overwritten by the conditional logic... wait, but for a plain gssp page without nonce and without ISR, no Cache-Control is set at all.Let me look at how this function is called and what options are passed. Let me look at the deploy.ts and pages-page-data.ts.
- If
Assistant
There's already a
NEVER_CACHE_CONTROLconstant that matches the expected default. Now let me look at howrenderPagesPageResponseis called to understand the flow.Assistant
Now let me understand the issue. The default Cache-Control for gssp should be
NEVER_CACHE_CONTROL="private, no-cache, no-store, max-age=0, must-revalidate".The current logic:
applyGsspHeadersis called, which sets user-set headers (including Cache-Control if user set it).- Then the conditional logic:
- If
scriptNonce→ overwrite withno-store, must-revalidate - Else if
isrRevalidateSeconds→ overwrite with revalidate cache control + cache state headers
- If
Assistant
Now let me look at how
createGsspReqResbuilds the res object, and whatgetHeadersreturns.Assistant
Now let me look at how
createGsspReqResis implemented in the pages-server-entry to understand thegetHeadersandsetHeaderbehavior:Assistant
Assistant
Let me look at the dev-server around line 500-600 and 1060 to understand how gssp Cache-Control is handled in dev mode. But the issue is about deploy mode. Let me focus on the deploy path which uses
renderPagesPageResponse.Let me look more carefully at the
renderPagesPageResponse. The default case: no nonce, no ISR. Then no Cache-Control is set. So the default should be NEVER_CACHE_CONTROL.But also the user-set case. Let me trace: user calls
res.setHeader("Cache-Control", "public, max-age=3600"). ThenresHeaders["cache-control"] = "public, max-age=3600". ThenapplyGsspHeaderssetsheaders.set("cache-control", "public, max-age=3600"). Then since no nonce, no ISR, nothing overwrites. So it should be preserved...Unless the issue is that
applyGsspHeadersdoesn't run for some reason. Wait, let me re-read the issue: "but vinext returns null". Let me actually reproduce this. Let me look at the existing tests for getserversideprops.Actually, let me think about the deploy path more. Let me check if there's a layer that strips Cache-Control after the response is built. Let me search for where the response is finalized in deploy mode.
Assistant
Let me focus on the deploy mode path since the issue is about deploy mode. The relevant file is
pages-page-response.ts. Let me look at the existing tests for getserversideprops to understand the expected behavior.Assistant
Now I understand the test cases. Let me look at the full final section of
renderPagesPageResponseagain and understand the precedence. Let me check whenscriptNonceis set.Assistant
Let me look at the dev-server around line 1050-1070 to understand the dev-mode Cache-Control logic for gssp, to keep parity.
Assistant
Assistant
Now I see a clear issue with the data request path. The
buildNextDataJsonResponsesets default headers and letsinit.headersoverride. But the call site:if (isDataReq) { const init = {}; if (gsspRes && gsspRes.headers) { // BUG: gsspRes.headers is undefined ... } return __buildNextDataJsonResponse(pageProps, safeJsonStringify, init); }gsspRes.headersis undefined because theresobject has no.headersproperty. It hasgetHeaders(). So for data requests, user headers are dropped AND no default Cache-Control is set.But wait, the issue mentions ~2 failures for
getserversideprops/test/index.test.ts. Let me figure out what those tests check. They probably check the HTML page response (not data). Let me write a reproduction test using the existing test harness pattern.Assistant
Reproduced. The default case fails (returns null), and the user-set case passes (returns the user value). So the "user setHeader dropped" part of the issue is actually about the data request path (
gsspRes.headersundefined bug). But the failing deploy tests are about the HTML page. Let me focus on:- Default Cache-Control for gssp HTML page → NEVER_CACHE_CONTROL (this is the failing case).
- Data request path:
gsspRes.headersshould begsspRes.getHeaders()(bug fix), and add default Cache-Control for data requests too.
Now let me look at the
isDataReqblock in pages-server-entry.ts to understand the structure.Assistant
This is a code generator that produces a string. Let me look at the exact lines around 700-730.
Assistant
Now I understand. The
gsspRes.headersis undefined becausereshas no.headersproperty. It should usegsspRes.getHeaders(). Let me fix both issues. First, the main fix inpages-page-response.ts.Assistant
Let me make the changes. First, update the import to include
NEVER_CACHE_CONTROL.Assistant
Now update the Cache-Control logic to add the gssp default:
Assistant
No python3. Let me use the edit command instead.
Assistant
Let me use the edit command directly:
Assistant
Now I'll edit the Cache-Control logic to add the gssp default branch:
Assistant
Now let me fix the data request path in pages-server-entry.ts. The
gsspRes.headersshould begsspRes.getHeaders(). Let me look at the generated entry imports and the data request block.Assistant
The data request path is generated code. Let me fix the
gsspRes.headers→gsspRes.getHeaders()bug and add a default never-cache for gssp data requests.Assistant
Now let me edit the data request block. I'll use
gsspRes.getHeaders()instead ofgsspRes.headers, and add the default never-cache for gssp data requests. Let me first check the imports section to add a cache-control constant import.Assistant
Let me add a cache-control path constant and import. First, let me check the path definitions at the top.
Assistant
Now add the import statement in the generated code. Let me add it next to the other imports:
Assistant
Now let me update the data request block to use
getHeaders()and add the default never-cache:Assistant
Wait, I need to reconsider the
elsebranch for the data request. Let me check existing tests for data routes to ensure I don't break getStaticProps data behavior.Assistant
The data-route tests for
buildNextDataJsonResponsedon't check Cache-Control. Let me be more conservative with theelsebranch — for non-gssp (getStaticProps/ISR) data requests, the original behavior was no Cache-Control, and ISR data requests should use revalidate policy, not never-cache. Let me revise to only handle the gssp case and leave non-gssp unchanged to avoid scope creep.Assistant
Now let me verify my main fix works with the repro test, then run existing relevant tests.
Assistant
Both pass now. Let me remove the repro test and run the existing relevant test suites.
Assistant
All pass. Now let me verify the entry template generation test still passes, since I modified the generated entry.
Assistant
These tests are excluded from the unit project (they're integration). Let me run them under the integration project.
Assistant
There's a test that calls
generateServerEntryand the generated code evaluation hits.headers is not a function. Let me look at the test.Assistant
This test only calls
generateServerEntryand checks the generated code string. The error must be ingenerateServerEntryitself. Let me check if this test was already failing before my change.Assistant
The whole generated entry is a template literal, and my comment contains backticks (
`.headers`), which terminate the template literal! Let me remove backticks from the comments inside the template literal.Assistant
Now let me re-run the entry-templates test to confirm it passes.
Assistant
Now let me verify the generated entry actually contains the new code properly. Let me write a quick inspection script.
Assistant
The integration project only includes specific files. Let me run it under the unit project.
Assistant
The generated entry now includes the import, the getHeaders() call, the default, and no legacy
.headers. Now let me run the broader unit test suite to ensure nothing breaks.Assistant
All unit tests pass. Now let me run the relevant integration tests that exercise the prod server entry (pages-router).
Assistant
All 241 pages-router integration tests pass. Let me check the e2e tests to see if there's a gssp page fixture I can verify end-to-end.
Assistant
There's a gssp
/ssrpage. Let me check its fixture and run an end-to-end verification by building and curling it.Assistant
Let me run an end-to-end build + serve to confirm the gssp page returns the default Cache-Control. Let me look at how the integration tests build and serve the prod server.
Assistant
Let me look at how the integration tests start the built prod server from the built entry.
Assistant
Let me write a temporary integration test that builds the pages-basic fixture and checks the Cache-Control on the /ssr gssp page. Let me see the full build setup of that test.
Assistant
Let me write a temporary integration test that builds the pages-basic fixture and checks Cache-Control on /ssr. Let me find a test that uses startProdServer with a full pages build.
Assistant
Let me look at how
startProdServeris used and whatoutDirit expects, and theunwrapStartedProdServerhelper. Let me look at line 2550-2575.Assistant
Let me look at lines 3080-3130 to see a complete build+startProdServer pattern.
Assistant
I have a good model. Let me write a temporary integration test that builds the pages-basic fixture and checks the Cache-Control on /ssr (gssp default).
Assistant
The integration project only includes specific files. Let me instead temporarily append a test into the existing pages-router.test.ts prod describe block, run it, then revert. Let me find that block.
Assistant
End-to-end verified: the gssp /ssr page returns the default never-cache. Now let me also verify the user-set override end-to-end by adding a temporary gssp page to the fixture.
Assistant
Underscore-prefixed pages are excluded from routing. Let me rename it.
Assistant
I accidentally removed the closing
});of the first TMP test. Let me fix the structure.Assistant
The first
itblock'stoBe(is unterminated — I dropped the);line. Let me fix it.Assistant
Now the structure is correct. The build caches in
dist; the beforeAll only rebuilds if entry.js doesn't exist. Let me remove the stale build to force a rebuild including the new cc-override page, then run both TMP tests.Assistant
Both end-to-end tests pass. Now let me verify the data request path (
/_next/data/<buildId>/ssr.json) end-to-end, since I fixed thegsspRes.headersbug there. Let me add a TMP test that extracts the buildId and fetches the data URL.Assistant
I again removed the closing
});of the user-set test. Let me fix it.Assistant
Now let me run all three TMP tests.
Assistant
All three end-to-end tests pass, including the data path fix. Now let me revert all my temporary changes: remove the TMP tests, the fixture page, and the dist build.
Assistant
Only my two intended source changes remain. Let me review the final diff and run the affected tests once more to confirm everything is clean.
Assistant
The diff is clean and minimal. Let me run the affected unit + integration tests once more to confirm everything passes.
Assistant
All tests pass (40 unit + 261 integration). Let me do a final review of the complete modified sections to ensure correctness.
Assistant
Let me also check the cloudflare worker entry, since the deploy suite runs against Cloudflare Pages too — there may be a separate data request path.
Assistant
The cloudflare entry uses the same generated
virtual:vinext-server-entryI fixed. Let me verify there's no separate cloudflare worker entry template with its own data path.Assistant
Let me check
prod-server.tsanddeploy.tsto ensure the response fromrenderPageisn't stripping Cache-Control anywhere.Assistant
Let me check prod-server.ts line 256 — it deletes headers in
targets. That's for matching some targets (probably hop-by-hop headers). Let me check whattargetsis to ensure Cache-Control isn't deleted. And lines 572/583 set Cache-Control for static files. Let me look at the context around 256.Assistant
stripHeadersonly strips hop-by-hop headers passed to it (not Cache-Control), and the e2e test confirmed Cache-Control reaches the client. My fix is complete and verified. Let me do a final git status check to ensure only the intended source files are modified and no temp files remain.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.