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.codeExpected: "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.
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) using or 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 analyze the issue. The problem is that Pages Router gssp (getServerSideProps) responses are missing
Cache-Controlheaders. Let me first explore the repository structure to understand the codebase and then find where the issue might be.Let me start by exploring the repository structure.
Assistant
Let me explore the repository structure more to understand how it's organized, particularly focusing on pages router and gssp handling.
Assistant
Let me look at the test files related to getserversideprops to understand what's expected.
Assistant
Let me look at the test files that might be related to gssp and Cache-Control:
Assistant
Let me look for tests related to pages router and gssp specifically.
Assistant
Let me search for gssp-related cache control tests:
Assistant
Let me look for the gssp cache control header tests more specifically:
Assistant
So the issue mentions that tests expect
private, no-cache, no-store, max-age=0, must-revalidatefor gssp pages. Let me look at the source code to understand how gssp responses are handled:Assistant
Let me look at the pages page response handling:
Assistant
Now I can see the issue. In
renderPagesPageResponse, theCache-Controlheader is only set in two cases:- When
options.scriptNonceis set:"no-store, must-revalidate" - When
options.isrRevalidateSecondsis truthy
But there's no default
Cache-Controlheader for gssp pages when neither of these conditions is met. Let me also check theapplyGsspHeadersfunction - it copies headers fromgsspResbut doesn't set a defaultCache-Control.Let me also look at how the
gsspResis created to see if the Cache-Control is supposed to be set there:- When
Assistant
Let me look at the pages-page-data.ts to understand how gsspRes is created and how headers are set:
Assistant
Now I understand the issue better. Let me look at how the response is built in
renderPagesPageResponse. The problem is:- When there's a gssp response, the code in
renderPagesPageResponseapplies gssp headers viaapplyGsspHeaders(), but then only setsCache-Controlin specific conditions (nonce or ISR). - For gssp pages without ISR and without nonce, no
Cache-Controlheader is set. - Additionally, if the user sets
Cache-Controlviares.setHeader()in gssp, it gets overridden by the conditional logic.
Let me check the exact flow:
- When there's a gssp response, the code in
Assistant
Now I see the issue clearly:
-
applyGsspHeaderscopies headers fromgsspRes(including any user-setCache-Control) toresponseHeaders -
But then the
if/else ifblock only setsCache-Controlwhen:options.scriptNonceis set →"no-store, must-revalidate"options.isrRevalidateSecondsis truthy → builds ISR cache control
-
When neither condition applies (normal gssp page), no
Cache-Controlis set. But Next.js expects gssp pages to default to"private, no-cache, no-store, max-age=0, must-revalidate". -
Also, if the user sets
Cache-Controlviares.setHeader()in gssp,applyGsspHeaderscopies it toresponseHeaders, but then the subsequentif/else ifcould potentially override it ifscriptNonceor is set.
-
Assistant
I need to look at the
NEVER_CACHE_CONTROLconstant and understand how it should be applied to gssp responses. Let me check the cache-control.ts file.Assistant
I see. Now let me look at the test files to understand what behavior is expected. Let me also check the pages-page-data-route.ts to understand the full flow:
Assistant
Now let me understand the full flow by looking at the dev-server.ts where gssp responses are handled:
Assistant
All reasoning completed. I need to fix the issue in pages-page-response.ts by adding default gssp Cache-Control. Let me make the edit now.
Assistant
The
opencommand seems to have issues. Let me try a different approach and useeditwith the--fileoption directly.Assistant
I need to:
- Import
NEVER_CACHE_CONTROLfrom./cache-control.js - Modify the
Cache-Controllogic inrenderPagesPageResponseto:- Apply the default gssp
Cache-Controlwhen there's a gssp response - Not override user-set
Cache-Controlfrom gssp
- Apply the default gssp
- Import
Assistant
Now I need to:
- Add
NEVER_CACHE_CONTROLto the import from./cache-control.js - Modify the Cache-Control logic to set the default for gssp pages and not override user-set headers
Let me first update the import:
- Add
Assistant
Now let me verify the import was updated:
Assistant
Good. Now let me look at the Cache-Control logic that needs to be modified:
Assistant
Now I need to modify this logic. The fix should:
- If
scriptNonceis set, useno-store, must-revalidate(this always overrides user headers) - If
isrRevalidateSecondsis set, use ISR cache control (this always overrides user headers) - If neither but there's a gssp response and no Cache-Control was already set, use the default gssp
NEVER_CACHE_CONTROL
Let me update the logic:
- If
Assistant
Let me use a more direct approach to replace the logic:
Assistant
Let me verify the change was applied correctly:
Assistant
The change looks good. Now let me also check the
applyGsspHeadersfunction to make sure it properly forwards the user-set Cache-Control header from gssp responses:Assistant
I see a potential issue. The
applyGsspHeadersfunction useskeydirectly forheaders.set(key, ...), but theCache-Controlheader from the user might be stored asCache-Control(case-sensitive) whileresponseHeaders.has("Cache-Control")checks case-insensitively (sinceHeadersis case-insensitive). Let me verify this is correct:Assistant
Good,
Headersis case-insensitive. Now let me run the existing tests to verify my changes work:Assistant
Let me run the pages router tests to verify my changes:
Assistant
Good, the unit tests are passing. Let me run the integration tests related to pages router:
Assistant
The tests are taking too long. Let me run a specific test file related to pages router:
Assistant
All 241 tests in pages-router.test.ts passed. Now let me also check if there are any tests that specifically test the Cache-Control header for gssp pages. Let me search for relevant test cases:
Assistant
Let me look at those specific tests to understand what they're testing:
Assistant
This test is checking for nonce-based cache control. Let me also check for tests that might specifically test the gssp default cache control behavior:
Assistant
Let me create a test script to verify my fix works:
Assistant
Interesting! The custom Cache-Control header test passes (which confirms
res.setHeaderis working), but the default test fails. This means my fix isn't being picked up in dev mode. The issue is that the dev server might use a different code path. Let me investigate.The test shows
Cache-Controlisnullfor the default gssp page. But the custom cache test passes, which meansapplyGsspHeadersis correctly forwarding the user-set header. So the issue is that the dev server uses a different response path thanrenderPagesPageResponse.Let me check the dev server code:
Assistant
Let me look at the dev server code more closely to understand how it handles gssp headers:
Assistant
I see! The dev server has the same issue. It also only sets
Cache-ControlwhenisrRevalidateSecondsis truthy. I need to fix this indev-server.tsas well. Let me see the full context:Assistant
Now I need to fix the dev server too. Let me also check what
gsspExtraHeaderscontains and how it's built:Assistant
Now I understand. The dev server collects gssp headers into
gsspExtraHeadersand then later applies them. The issue is that whenisrRevalidateSecondsis not set and there's a gssp page, no default Cache-Control is emitted. Let me fix the dev server:Assistant
The test timed out. I need to run a more targeted test or check if my changes are correct. Let me check the dev-server.ts to see what imports it already has and then apply the fix there as well.
Assistant
I need to check if
NEVER_CACHE_CONTROLneeds to be imported in dev-server.ts as well. Let me check the imports more carefully:Assistant
I see that
NEVER_CACHE_CONTROLis not imported indev-server.ts. Let me add the import and fix the Cache-Control logic in the dev server:Assistant
Now I need to fix the Cache-Control logic in the dev server. The relevant section is around line 1060:
Assistant
Now I need to modify this block to also handle the gssp default Cache-Control case. The logic should be:
- If
scriptNonceis set, override withno-store, must-revalidate - If
isrRevalidateSecondsis set, use ISR cache control - Otherwise, if there's a gssp page and no user-set Cache-Control, use the default
NEVER_CACHE_CONTROL
- If
Assistant
The shell is having issues with the backticks and special characters. Let me write the script to a file instead:
Assistant
Let me verify the change:
Assistant
Let me also verify the import was added correctly:
Assistant
Now let me run my test again to see if the dev server fix works:
Assistant
Progress! Now the first test passes (default Cache-Control is set), but the second test fails because my condition
!gsspExtraHeaders["Cache-Control"]doesn't properly detect the user-set header. The issue is that the header key might have different casing (e.g., "cache-control" vs "Cache-Control").Let me debug this:
Assistant
I see. The
gsspExtraHeadersis populated with the exact key casing fromres.getHeaders(). In Node.js,res.getHeaders()returns keys in lowercase. Let me verify:Assistant
As I suspected, the key is lowercase
'cache-control', not'Cache-Control'. So my check!gsspExtraHeaders["Cache-Control"]doesn't find it because the actual key is'cache-control'. I need to check case-insensitively:Assistant
Now let me run the test again:
Assistant
Both tests pass now. Let me also clean up my test file and run the existing pages-router tests to make sure I didn't break anything:
Assistant
Assistant
All 241 tests still pass. Let me now verify the changes I made are correct by checking both files:
Assistant
Now let me check if there are any other server files that might need the same fix (e.g., production server entry points):
Assistant
Let me also check the production server to see if it uses a different code path:
Assistant
The
prod-server.tsdoesn't directly reference gssp or renderPagesPageResponse. Let me check the production server entry point to understand how it handles pages router responses.Assistant
The production server uses
renderPagesPageResponsefrom the pages-server-entry.ts, which calls the function I already fixed. So my fix inpages-page-response.tsshould handle the production path as well.Let me also check the entries/pages-server-entry.ts to make sure the production server path also works:
Assistant
The previous command seemed to have issues. Let me continue verifying the changes and run the existing tests to make sure everything works.
Assistant
All 241 tests pass. Let me also run the unit tests to make sure nothing else broke:
Assistant
All tests pass. Let me summarize the changes I made and verify the final state of the modified files:
Assistant
Let me continue with the summary and verification.
Assistant
The changes look correct. Let me provide a summary of my fix and submit.
Summary of Changes
I fixed the issue where Pages Router gssp (getServerSideProps) responses were missing the
Cache-Controlheader. The fix addresses two issues:-
Default gssp Cache-Control not applied: GSSP pages now get the default
Cache-Control: private, no-cache, no-store, max-age=0, must-revalidateheader. -
User-set Cache-Control via
res.setHeader()preserved: If the user sets a customCache-Controlheader ingetServerSideProps, it is now preserved and not overridden.
Files Modified
-
- Production server path:
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.