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
I'll start by exploring the repository to understand its structure and locate relevant files. Let's first get a high-level view.
- Assistant
Let me explore the repository structure more.
- Assistant
Let me look at the test file mentioned in the issue to understand what's expected.
- Assistant
Let me look at the specific test suite mentioned in the issue and the relevant source code.
- Assistant
The issue mentions the test suite is at
test/e2e/getserversideprops/test/index.test.tsbut this repository seems to have a different structure. Let me look at the pages-router related tests and source code. - Assistant
Let me search for getServerSideProps related test files.
- Assistant
Let me look for cache-control tests in the pages router tests:
- Assistant
Let me search more specifically for Cache-Control header tests related to getServerSideProps.
- Assistant
No direct Cache-Control string in pages-router.test.ts. Let me look at the cache-control test file and the pages-page-response test:
- Assistant
Let me look for the gssp Cache-Control handling in the pages router response handling code. The issue says the default Cache-Control header
private, no-cache, no-store, max-age=0, must-revalidateshould be set for gssp (getServerSideProps) responses. - Assistant
Let me look at the pages-page-response test more carefully, especially around cache-control and getServerSideProps.
- Assistant
Let me look at the test that's failing - the issue mentions
test/e2e/getserversideprops/test/index.test.tsbut I don't see that path. Let me search for gssp-related tests: - Assistant
Let me search for gssp Cache-Control default header in the source code.
- Assistant
Let me look at how getServerSideProps pages handle cache control in the source code.
- Assistant
Let me search for files related to pages router server-side rendering and cache control.
- Assistant
Let me look at the pages-page-response.ts file, which is likely where the cache control header should be set for gssp responses.
- Assistant
Now I understand the codebase. Let me look at the issue more carefully. In
renderPagesPageResponse, the code handles Cache-Control for script nonce and ISR pages, but doesn't set a default Cache-Control for gssp (getServerSideProps) pages. Let me check thecache-control.tsfile and find where the default header should be applied. - Assistant
Now let me understand the issue more clearly. Let me look at how the pages router handles getServerSideProps responses:
- Assistant
Let me check the full renderPagesPageResponse function to see where Cache-Control should be set:
- Assistant
Now I understand the issue. In
renderPagesPageResponse, there are three cases for Cache-Control:scriptNonce→ sets "no-store, must-revalidate"isrRevalidateSeconds→ sets ISR cache control- gssp (getServerSideProps) pages → no Cache-Control is set at all!
The fix is to add a default
Cache-Control: private, no-cache, no-store, max-age=0, must-revalidatefor gssp pages when no Cache-Control has been explicitly set (by the user or by ISR/nonce logic).Let me check what the
NEVER_CACHE_CONTROLconstant is: - Assistant
Now let me implement the fix. I need to:
- Import
NEVER_CACHE_CONTROLfrom cache-control.ts - Add logic to set default Cache-Control for gssp pages when no Cache-Control is set
- Import
- Assistant
Now let me modify the file to import NEVER_CACHE_CONTROL and add the default Cache-Control for gssp pages.
- Assistant
Let me look at the section where headers are set:
- Assistant
Now I see the problem clearly. After
applyGsspHeaderscopies headers from the gSSP response, the code only sets Cache-Control ifscriptNonceorisrRevalidateSecondsis set. But for a plain getServerSideProps page (wheregsspResis non-null butscriptNonceis undefined andisrRevalidateSecondsis null/0), no Cache-Control header is set at all.The fix needs to:
- Import
NEVER_CACHE_CONTROL - When
gsspResis non-null and the user hasn't set Cache-Control explicitly, set the default NEVER_CACHE_CONTROL - If the user has set Cache-Control via
res.setHeaderduring gSSP, preserve it
Let me look at the
applyGsspHeadersfunction more closely: - Import
- Assistant
Now I understand the issue. The problem is in
renderPagesPageResponse. AfterapplyGsspHeaderscopies user-set headers (including a user-setCache-Control), the code only sets Cache-Control whenscriptNonceorisrRevalidateSecondsis set. For a plain gSSP page (non-nullgsspRes, no ISR), no default Cache-Control is applied. The user's override would be preserved throughapplyGsspHeaders, but the default is missing.Let me apply the fix:
- Assistant
Let me use the replace command instead.
- Assistant
Let me navigate to line 6 first.
- Assistant
Now let me edit the import line on line 6.
- Assistant
Let me try with the replace command differently.
- Assistant
Good, now I need to add the default Cache-Control for gssp pages. Let me navigate to line 377 where the headers are set.
- Assistant
Now I'll add the default Cache-Control for gssp pages. I need to add an
elseclause to handle the case wheregsspResis non-null but no Cache-Control has been set yet. Let me edit lines 379-387. - Assistant
The edit command isn't accepting the file parameter. Let me use replace command with the correct syntax.
- Assistant
Now let me verify the changes look correct by examining the modified function:
- Assistant
Good, the change looks correct. Now let me also check if there's any handling needed in the
pages-data-route.tsorpages-data-routefor_next/dataresponses (which is the JSON data endpoint for getServerSideProps pages). Let me look at that: - Assistant
Let me check where the data route responses are handled for getServerSideProps - the
_next/dataendpoint. Let me search for how gSSP data is returned: - Assistant
Let me look at how the pages-server-entry.ts uses buildNextDataJsonResponse to see if it also needs the Cache-Control header for data responses.
- Assistant
Let me look at the context around line 684-721 in the pages-server-entry.ts to understand how the gSSP data response is built.
- Assistant
I see the issue - for the data request (
isDataReq), the code forwards headers from gsspRes but doesn't set a default Cache-Control. Let me check if the data route also needs the default Cache-Control. In Next.js, both HTML and JSON data responses for getServerSideProps should have the default Cache-Control header.Let me also check the pages-data-route.ts to see how buildNextDataJsonResponse handles headers:
- Assistant
Now let me check the existing test in pages-page-response.test.ts to understand the expected behavior. Let me also look at how the data route handles Cache-Control:
- Assistant
Now I see - the data request path (line 708-721) also needs the Cache-Control fix. When
isDataReqis true, the code builds a JSON response with__buildNextDataJsonResponse, passinginit.headerswhich contains the gSSP response headers. However, it doesn't set a default Cache-Control header for gSSP data responses.Let me check if the
NEVER_CACHE_CONTROLconstant is imported in the pages-server-entry.ts: - Assistant
Let me look at the pages-server-entry.ts file to understand the data request path:
- Assistant
Now let me look at the pages-server-entry.ts to understand the data request path better:
- Assistant
I need to also fix the data request path in
pages-server-entry.ts. WhenisDataReqis true and it's a gSSP page, the code needs to set a default Cache-Control header unless the user already set one. Let me check the structure of pages-server-entry.ts: - Assistant
Let me look at the relevant section of pages-server-entry.ts more closely to understand the data request flow:
- Assistant
Let me now also fix the data request path. I need to add the default Cache-Control for gSSP pages in the data request path too:
- Assistant
I need to also import NEVER_CACHE_CONTROL in the pages-server-entry.ts file and use it for the data request path. Let me check how the import works:
- Assistant
Let me also look at how the pages-server-entry.ts imports things. I need to add an import for
NEVER_CACHE_CONTROL: - Assistant
Let me look at the beginning of the pages-server-entry.ts file:
- Assistant
Let me see what other paths are defined:
- Assistant
Let me add the cache-control module path and import. First, add the path:
- Assistant
Now let me add the cache-control path and import. First, add the path constant:
- Assistant
Let me use the replace command instead:
- Assistant
Now I need to add the import for NEVER_CACHE_CONTROL in the generated code. Let me find where the imports are being generated:
- Assistant
Let me add the import for NEVER_CACHE_CONTROL after the CSP import:
- Assistant
Let me navigate to that line first.
- Assistant
Now I can see the exact line. Let me add the import for NEVER_CACHE_CONTROL after the CSP import on line 241:
- Assistant
Now let me update the data request handling to also set the default Cache-Control header. Let me navigate to the isDataReq section:
- Assistant
Now let me update the data request handling to also set the default Cache-Control header when it's a gSSP page and no Cache-Control has been explicitly set:
- Assistant
Let me navigate to the line first.
- Assistant
Now let me try the replace command again with the exact text:
- Assistant
Now let me also check if there's a similar issue in the
pages-page-data.tsfile. Let me look at that: - Assistant
Good. Now let me also check if there's something similar needed in the
pages-page-data.tsfile, or if the current fix is sufficient. Let me look at the ISR path inpages-page-response.tsmore carefully to see if the Cache-Control should also apply to ISR+gSSP paths: - Assistant
The logic looks correct:
scriptNonce→ "no-store, must-revalidate" (always overrides)isrRevalidateSeconds→ ISR cache control (always overrides)gsspRespresent + no Cache-Control already set → NEVER_CACHE_CONTROL (default for gSSP)
This correctly handles user-set Cache-Control overrides because
applyGsspHeaderscopies them first, soresponseHeaders.has("cache-control")will be true if the user set one.Now let me run the relevant tests. First, let me find the test runner:
- Assistant
Let me run the pages-page-response test first:
- Assistant
Let me try a different approach:
- Assistant
Let me try running the test with the project's own runner:
- Assistant
Let me check how the test runner works.
- Assistant
Let me try to use vp test run directly with a filter for the specific test file.
- Assistant
All existing tests pass. Now let me also run the pages-router.test.ts tests which seem to cover getServerSideProps:
- Assistant
All 241 tests pass. Let me also run the cache-control tests to make sure:
- Assistant
Now let me also check if there are any tests that specifically test the Cache-Control header for gSSP pages. Let me look at the pages-page-data.test.ts:
- Assistant
Let me check if there are any e2e tests related to gSSP cache-control headers:
- Assistant
Let me also search for cache-control assertions in the pages-router.test.ts to see if there are existing tests for gSSP cache control:
- Assistant
Let me look at those specific lines to understand what they're testing:
- Assistant
Let me check the SSR page test to see if it checks Cache-Control:
- Assistant
Let me look at the "getServerSideProps headers and status are applied to the response" test:
- Assistant
Now let me search for the exact test that checks the default Cache-Control for gSSP pages:
- Assistant
Let me look at the test fixture pages that use getServerSideProps to understand the structure better:
- Assistant
Let me check the
ssr-headers.tsxpage that usesres.setHeaderto set a custom header: - Assistant
Let me check the ssr page fixture:
- Assistant
Now let me check if there are any tests that check Cache-Control for the
/ssrpage or/ssr-headerspage. Let me search for those in the pages-router.test.ts: - Assistant
Let me look at the test for the ssr page to see if it checks Cache-Control:
- Assistant
Let me look at the test that's mentioned in the issue. Let me also look at the
pages-page-data.test.tsfile which handles the JSON data route: - Assistant
Let me look at the pages-page-data.test.ts file which handles the JSON data route:
- Assistant
Let me check if there's another path for the data route where Cache-Control might be missing. Let me look at how
pages-page-data.tshandles gSSP: - Assistant
Let me look at the
resolvePagesPageDatafunction to understand how gSSP responses are handled there: - Assistant
Let me look at how
createGsspReqRes()works to understand what headers theresobject has: - Assistant
Let me look at the pages-node-compat.ts file to understand how createGsspReqRes works:
- Assistant
Let me look at how the response is returned from
resolvePagesPageDataand then used in the server entry: - Assistant
Let me check the
res.setHeaderimplementation to understand how headers are stored: - Assistant
I see that
setHeaderstores keys in lowercase. So when checking for user-set Cache-Control, I need to account for the lowercase key. My check in the data route path checks bothCache-Controlandcache-control, which is correct.Now let me run the full test suite for the pages-related tests to make sure everything works:
- Assistant
All tests pass. Now let me create a small test script to verify the fix works correctly by testing the Cache-Control header behavior:
- Assistant
Let me use the existing test framework properly instead. Let me verify by looking at the dist directory:
- Assistant
Let me check whether the existing pages-router tests verify Cache-Control on gssp responses. The test for
/ssr(a gSSP page) doesn't check Cache-Control currently. Let me also verify the fix works by looking at the existing test for gSSP headers: - Assistant
Let me also check the e2e tests that might be relevant:
- Assistant
Let me check if there's a specific test for the pages-router-prod that checks Cache-Control for gSSP pages:
- Assistant
Let me now verify the dist file was updated. Let me check if there's a dist version that needs to be updated:
- Assistant
Good, the NEVER_CACHE_CONTROL is already exported from the dist file. Now let me check if there's a dist file for pages-page-response.ts that also needs updating:
- Assistant
Let me check if the dist file is out of date:
- Assistant
The dist file doesn't have the fix yet. But the tests import from the source directory directly, so the tests will use the source files. Let me verify this by looking at the test file's imports:
- Assistant
Good - the tests import from the source directory. Let me now run all the relevant tests to make sure nothing is broken:
- Assistant
Now let me run the pages-router.test.ts one more time to confirm:
- Assistant
All 241 tests pass. Let me now review the changes I made by looking at the diff:
- Assistant
Let me also review the actual diff to make sure it's correct:
- Assistant
The diff looks correct. Let me now run a broader test suite to make sure nothing else is broken. Let me also check the
pages-page-data.test.tsandfeatures.test.ts: - Assistant
Let me also run the
features.test.tswhich is a larger test file:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.