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.
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 statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /vinext, current file: none) bash-$
- Assistant
I'll start by exploring the repository structure to understand the codebase and locate relevant files. Let's first get an overview.
- Assistant
Let me look at the repository structure more carefully. It seems to be a monorepo with packages.
- Assistant
Let me explore the test file mentioned in the issue to understand what's expected.
- Assistant
The test file mentioned in the issue doesn't seem to exist in this repository directly. Let me search more broadly.
- Assistant
Let me search more broadly for test files related to gssp or cache-control.
- Assistant
Let me look at the source files, not just dist files.
- Assistant
Let me search for the relevant source files related to pages router and getServerSideProps.
- Assistant
Let me look at the pages-page-response.ts and pages-page-data.ts files, as these are likely where the Cache-Control headers should be set for getServerSideProps responses.
- Assistant
Let me look at the pages-page-data.ts and headers.ts to understand how Cache-Control is handled.
- Assistant
Let me look at the
cache-control.tsfile to understand the default cache control logic, and theprod-server.tsto see how the response is assembled. - Assistant
Now let me look at the prod-server.ts to see how pages responses are handled.
- Assistant
Let me look at the test file to understand what's expected.
- Assistant
Let me look at the test files to understand what's expected for GSSP Cache-Control headers.
- Assistant
Let me look at the pages router test file to find Cache-Control assertions.
- Assistant
Let me search more broadly.
- Assistant
Let me search for the specific test mentioned in the issue.
- Assistant
Let me look at the pages-page-response test file to understand the testing structure.
- Assistant
Let me understand the flow better. Let me look at the existing test for gssp headers and the deploy test file.
- Assistant
Let me look at how
createGsspReqResworks to understand the response object passed to getServerSideProps: - Assistant
Let me check how gssp req/res is created in the pages-server-entry.ts:
- Assistant
Let me find the __createPagesReqRes function:
- Assistant
Let me look for the pages-node-compat file:
- Assistant
Let me examine the pages-node-compat.ts file:
- Assistant
Now I understand the issue. Let me trace the code flow. The problem is in
pages-page-response.ts. Let me look at the relevant section: - Assistant
Let me look at the relevant code around the Cache-Control logic to understand the issue better.
- Assistant
Now I understand the issue. Let me verify my understanding by checking how the import works and what the fix should be:
- Assistant
Now I understand the issue. Looking at the code in
renderPagesPageResponse, I can see that:applyGsspHeaders()applies headers set by the user viares.setHeader()duringgetServerSideProps- Cache-Control is only set when
scriptNonceorisrRevalidateSecondsare present - For gssp pages (getServerSideProps),
isrRevalidateSecondsisnull, so no default Cache-Control is set
The fix is to set a default
Cache-Control: private, no-cache, no-store, max-age=0, must-revalidatefor gssp pages when no Cache-Control is already set. Let me also look at how the test expects this: - Assistant
Let me look at the test files related to gssp to understand what they expect. Let me check the deploy test and the pages router test:
- Assistant
Now I understand the issue. Let me trace the code:
- In
renderPagesPageResponse,applyGsspHeadersapplies user-set headers from gsspRes (which includesres.setHeadercalls during getServerSideProps) - Cache-Control is only set in two cases:
scriptNonce→no-store, must-revalidate, orisrRevalidateSeconds→ ISR cache control - For gssp pages,
isrRevalidateSecondsisnull, so no default Cache-Control header is set
The fix needs to:
- Set a default
Cache-Control: private, no-cache, no-store, max-age=0, must-revalidatefor gssp pages when no Cache-Control was already set - Preserve user-set Cache-Control headers from
res.setHeader
Let me also check what
NEVER_CACHE_CONTROLconstant looks like: - In
- Assistant
Now I understand the issue completely. Let me implement the fix.
The problem is in
pages-page-response.ts. When rendering a gssp page (getServerSideProps), there's no default Cache-Control header set. In Next.js, gssp pages should haveCache-Control: private, no-cache, no-store, max-age=0, must-revalidateby default, and user-set headers viares.setHeader('Cache-Control', ...)should be preserved.The fix needs to:
- Import
NEVER_CACHE_CONTROLfrom./cache-control.js - Add a condition after the existing Cache-Control logic to set the default for gssp pages when no Cache-Control was already set
- Import
- Assistant
Let me look at the exact code to modify in pages-page-response.ts:
- Assistant
Now I understand the issue. Let me look at how the existing test handles the gssp case without Cache-Control:
- Assistant
Let me check the pages-page-data test to see if there are tests related to gssp Cache-Control:
- Assistant
Let me look at the test cases around those lines to understand the context better.
- Assistant
Now I understand the issue. Let me trace through the code:
- In
pages-page-response.ts, therenderPagesPageResponsefunction creates response headers - It applies gssp headers via
applyGsspHeaders()which includes user-set headers fromres.setHeader() - Cache-Control is only set in two cases:
scriptNonce→no-store, must-revalidateisrRevalidateSeconds→ ISR cache control
The problem is that for gssp pages (getServerSideProps),
isrRevalidateSecondsisnull, so no default Cache-Control is set. In Next.js, gssp pages should getCache-Control: private, no-cache, no-store, max-age=0, must-revalidateunless the user explicitly sets it viares.setHeader.However,
gsspResis set for bothgetServerSidePropsandgetStaticPropspages. We need to distinguish between the two to know when to apply the default.Let me look at how the test expects this behavior:
- In
- Assistant
Let me look at the pages-server-entry.ts to understand how the response is assembled:
- Assistant
Let me search for where
renderPagesPageResponseis called with gsspRes: - Assistant
Let me look at lines 710-780 to understand how the gsspRes is used.
- Assistant
Now I understand the issue completely. Let me look at how
buildNextDataJsonResponseworks to understand the data request path: - Assistant
Now I understand the issue completely. Let me trace through the code:
- In
pages-page-response.ts,renderPagesPageResponsecreates response headers applyGsspHeaderscopies user-set headers from gsspRes- Cache-Control is only set when
scriptNonceorisrRevalidateSecondsare present - For gssp pages (getServerSideProps),
isrRevalidateSecondsis null, so NO default Cache-Control is set
The problem is that
gsspResis set for BOTHgetServerSidePropsandgetStaticPropspages, but we need to distinguish them:getServerSidePropspages: should get defaultCache-Control: private, no-cache, no-store, max-age=0, must-revalidateunless user overridesgetStaticPropspages: get ISR cache control or no default
Let me implement the fix. I need to:
- Add a
gsspflag toResolvePagesPageDataRenderResultinpages-page-data.ts - Set it to true only in the getServerSideProps path
- Use it in
renderPagesPageResponseto set the default Cache-Control - Import
NEVER_CACHE_CONTROLin pages-page-response.ts
- In
- Assistant
Let me look at how the data request path handles headers:
- Assistant
Now I understand the issue completely. Let me trace through the code:
- In
pages-page-response.ts,renderPagesPageResponsecreates response headers applyGsspHeaderscopies headers from gsspRes (which includes user-set headers viares.setHeader)- Cache-Control is only set when
scriptNonceorisrRevalidateSecondsare present - For gssp pages (getServerSideProps),
isrRevalidateSecondsis null, so no default Cache-Control is set
The fix needs to:
- Set default Cache-Control for gssp pages when no Cache-Control was already set
- Import
NEVER_CACHE_CONTROLfrom cache-control.ts
Let me first check the existing test to understand what's expected:
- In
- Assistant
Now I understand the issue completely. Let me implement the fix:
-
In
pages-page-response.ts:- Import
NEVER_CACHE_CONTROLfrom./cache-control.js - After the existing Cache-Control logic, add a condition for gssp pages when no Cache-Control was already set
- Import
-
The key insight is:
gsspResis set for getServerSideProps pages (whereisrRevalidateSecondsis null)- For ISR pages (getStaticProps with revalidate),
isrRevalidateSecondsis set and Cache-Control is handled - The user-set headers via
res.setHeaderare already copied byapplyGsspHeaders
Let me implement the fix:
-
- Assistant
Let me implement the fix. I need to:
- Import
NEVER_CACHE_CONTROLinpages-page-response.ts - Add a condition after the existing Cache-Control logic to set default Cache-Control for gssp pages when no Cache-Control was already set
- Import
- Assistant
Now I'll implement the fix. First, update the import:
- Assistant
Let me open the file and use the edit command properly.
- Assistant
Now I can edit the file. Let me update the import first:
- Assistant
Let me use sed to make the changes:
- Assistant
Now let me add the default Cache-Control for gssp pages. First, let me check the current code around line 380:
- Assistant
Now I understand the issue. The problem is in the
renderPagesPageResponsefunction. For GSSP (getServerSideProps) pages:gsspResis set (it's the response object from GSSP)isrRevalidateSecondsis null (GSSP pages don't use ISR)- The code only sets Cache-Control if
scriptNonceorisrRevalidateSecondsis set - So GSSP pages get NO default Cache-Control header
The fix is to add an
elsecase that sets the defaultNEVER_CACHE_CONTROLfor GSSP pages when no ISR or scriptNonce is set. This preserves user-set Cache-Control because:- User-set headers from
res.setHeaderare applied byapplyGsspHeaders(line 377) - If scriptNonce is set, it overrides with
no-store, must-revalidate - If isrRevalidateSeconds is set, it overrides with ISR cache control
- Otherwise (GSSP without scriptNonce), we set the default NEVER_CACHE_CONTROL
Let me also check how
gsspResis set to understand the distinction: - Assistant
Now I need to add the default Cache-Control for gssp pages. Let me also check the data request path to make sure it handles Cache-Control too:
- Assistant
Now let me also check the data request path. The data request path (
isDataReq) forwards headers from gsspRes but doesn't set a default Cache-Control. Let me add the fix inpages-page-response.ts: - Assistant
Now let me also check the data request path. Looking at lines 711-725, the data request path also needs the default Cache-Control for gSSP pages:
- Assistant
Now I need to add the default Cache-Control for gssp pages. The fix needs to be in
renderPagesPageResponse- after the existing Cache-Control logic, add a condition for gssp pages when no Cache-Control was already set.Let me first verify the import was added correctly:
- Assistant
Now I need to add the logic for setting default Cache-Control for gssp pages. Let me also check the data request path in
pages-server-entry.tsto see if it needs the same fix: - Assistant
Let me look at the pages-page-data.ts to understand how the result is returned:
- Assistant
Now I understand the issue. Let me implement the fix. The problem is that in
renderPagesPageResponse, Cache-Control is only set whenscriptNonceorisrRevalidateSecondsare set. For gssp pages (getServerSideProps),isrRevalidateSecondsis null, so no default Cache-Control is set.I need to:
- Add default Cache-Control for gssp pages in
renderPagesPageResponse - Also handle the data request path in
pages-server-entry.ts
Let me first add the fix to
pages-page-response.ts: - Add default Cache-Control for gssp pages in
- Assistant
Let me try using node instead:
- Assistant
Now let me also fix the data request path in
pages-server-entry.ts: - Assistant
Let me verify the changes I made:
- Assistant
Let me search for the specific section I modified:
- Assistant
Now let me verify the change in pages-server-entry.ts:
- Assistant
Good. Now let me also check the gsspRes.headers handling in pages-node-compat.ts to make sure
res.setHeader('Cache-Control', ...)stores lowercase 'cache-control': - Assistant
Good. I can see that
setHeaderstores keys in lowercase:resHeaders[name.toLowerCase()] = Array.isArray(value) ? value.join(", ") : value;So the check for
"cache-control"will work. Now let me run the existing tests to make sure my changes don't break anything: - Assistant
Let me try using the available test runner:
- Assistant
Let me check what test runner is used:
- Assistant
Let me run the tests using the project's test runner:
- Assistant
Now let me also run the pages-page-data tests:
- Assistant
Now let me run the pages-router tests:
- Assistant
The integration test failure is likely caused by my TypeScript type annotation in
pages-server-entry.ts. The file generates a JavaScript entry module, so I need to remove the type annotation: - Assistant
Let me look at the original code in pages-server-entry.ts to understand the issue:
- Assistant
I see the issue - this is a TypeScript file that generates JavaScript code as strings. The TypeScript type annotation will be emitted as-is into the generated JS module, causing a syntax error. Let me revert that change and fix it properly:
- Assistant
Let me check the exact context of this file to understand if this is source code or generated code:
- Assistant
Wait, looking at this more carefully, this is a TypeScript source file that generates JavaScript code as strings. Let me check if the area I modified is part of the generated code or TypeScript source code:
- Assistant
Let me check the current state of the data request handling:
- Assistant
Wait, I need to look at this more carefully. The
pages-server-entry.tsfile generates JavaScript code as a template string. Let me check if the code I modified is part of the template string or TypeScript source: - Assistant
I see - this is a template literal string starting at line 209. The code at line 710+ is inside this template literal. So the code I modified is generated JavaScript, not TypeScript source. Let me verify the current state is correct (no TypeScript annotations):
- Assistant
Good, the code is inside a template literal. My changes look correct now - I removed the TypeScript annotation and the code should be valid JavaScript. Let me verify the current state:
- Assistant
Let me run the failing test again to see if it passes now:
- Assistant
Now let me also verify the data request path. Let me check the
buildNextDataJsonResponsefunction to see if it properly forwards headers: - Assistant
Good. The
buildNextDataJsonResponsefunction mergesinit?.headersinto the response headers. Let me now write a quick test to verify the fix works: - Assistant
Let me just run the existing tests to make sure everything passes:
- Assistant
Now let me also write a temporary test to verify the fix works:
- Assistant
Let me also run the full test suite to make sure nothing is broken:
- Assistant
Let me run the unit tests only:
- Assistant
All unit tests pass. Let me also run the integration tests:
- Assistant
Let me run just the key pages-router integration test:
- Assistant
All tests pass. Let me verify my changes are correct by reviewing the diff:
- Assistant
The changes look good. Let me also check if there are any edge cases I need to consider. Let me verify the behavior of
setCacheStateHeaders: - Assistant
Good. The
setCacheStateHeadersfunction only setsVINEXT_CACHE_HEADERandNEXTJS_CACHE_HEADER(for cache state), notCache-Control. So that's fine.Let me now also verify that the data request path works correctly. Let me look at how
buildNextDataJsonResponsehandles the headers: - Assistant
Now let me verify that the header check in pages-server-entry.ts works correctly. The headers from
res.setHeaderare stored with lowercase keys inpages-node-compat.ts: - Assistant
Let me check if the
setHeadermethod stores the header with lowercase keys: - Assistant
The
setHeadermethod stores headers with lowercase keys (name.toLowerCase()). So if the user callsres.setHeader('Cache-Control', 'public, max-age=3600'), it will be stored ascache-control: 'public, max-age=3600'in the headers object.In the data request path, I check
!init.headers?.["cache-control"], which is correct because the headers are stored with lowercase keys.Let me now run the full test suite to make sure everything is working correctly:
- Assistant
All 4755 unit tests pass. Let me verify the final state of my changes:
- Assistant
Let me do a final review of the complete diff:
- Assistant
The changes look correct. Let me now verify one more edge case - when the user explicitly sets Cache-Control via
res.setHeader:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →