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 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 structure to understand what we're working with. Let's first check the current directory and see the overall layout.
- Assistant
Let me explore the repository structure more thoroughly to understand what we're working with.
- Assistant
This looks like a monorepo with packages, apps, tests, etc. Let me understand the structure better.
- Assistant
Let me look at the structure more carefully.
- Assistant
Let me explore the source directory to understand the project structure better.
- Assistant
Let me look at more source files and understand the overall structure better.
- Assistant
Let me look at the relevant test file and the pages server handling code.
- Assistant
Let me look at the test directory structure.
- Assistant
Let me look at the e2e test directory mentioned in the issue and also the relevant pages router files.
- Assistant
I need to find the relevant test file mentioned in the issue:
test/e2e/getserversideprops/test/index.test.ts. Let me search for it. - Assistant
Let me look at the pages-router and pages-router-prod e2e tests:
- Assistant
Let me look at the deploy test and the pages page response code, which seems to be the most relevant:
- Assistant
The issue mentions
test/e2e/getserversideprops/test/index.test.tsbut that path might not exist yet. Let me search for getServerSideProps-related tests in the existing test files. - Assistant
Let me search for the Cache-Control related code and understand how pages data routes work:
- Assistant
Let me look at the pages-page-response.ts file to understand how Cache-Control is handled for GSSP pages:
- Assistant
Now let me look at the pages-page-data.ts file to see how getServerSideProps data routes are handled:
- Assistant
Now I need to understand the issue better. Let me search for where Cache-Control headers are set for GSSP responses:
- Assistant
Let me continue exploring the codebase to understand the issue.
- Assistant
Now let me look at the
pages-page-response.tsmore carefully, specifically therenderPagesPageResponsefunction. In that function, I can see that for GSSP responses:- If
options.scriptNonceis set, it setsCache-Control: no-store, must-revalidate - If
options.isrRevalidateSecondsis set (ISR), it sets Cache-Control based on revalidation settings - But there's no explicit handling for the default case of GSSP (when neither condition is true)
Looking at the
renderPagesPageResponsefunction around lines 300-330, I see:I'm examining the Cache-Control logic where GSSP responses without script nonces or ISR revalidation settings don't get a Cache-Control header set at all, which means they're missing the default no-cache behavior that should apply to server-side rendered content. The real problem is that the cache control logic doesn't handle the default case for SSR pages—if there's no script nonce, no ISR revalidation, and the page came from getServerSideProps, it needs to set that cache-control header to prevent caching. Looking at the
applyGsspHeadersfunction, it's handling the response headers but not accounting for this scenario. - If
- Assistant
Let me look at how pages server entries handle gssp responses and where the cache-control header should be set:
- Assistant
Let me look at how the gssp response object is created:
- Assistant
Let me look at the
createGsspReqResfunction implementation: - Assistant
Let me find the
__createPagesReqResfunction: - Assistant
Let me look at the
pages-node-compat.tsfile which creates the request/response objects: - Assistant
Let me look at the
pages-page-response.tsin full to understand the logic aroundCache-Controlfor gssp pages: - Assistant
Let me look at the full
renderPagesPageResponsefunction and theapplyGsspHeadersfunction to understand the flow: - Assistant
Now let me understand the flow. Let me look at the pages-page-data.ts to see what happens with gsspRes:
- Assistant
Let me look at the pages-server-entry.ts to see how gsspRes is used when rendering a page response:
- Assistant
Now I understand the issue. Let me trace through the flow:
- In
renderPagesPageResponse,applyGsspHeaderscopies headers fromgsspRes.getHeaders()to the response - Then the Cache-Control logic only sets Cache-Control if
scriptNonceorisrRevalidateSecondsis set - For gssp pages (getServerSideProps), neither condition is true, so no Cache-Control is set by default
- Also, in the data request path,
gsspRes.headersis accessed (which is undefined) instead ofgsspRes.getHeaders()
Let me look at existing tests to understand the expected behavior:
- In
- Assistant
Let me look at the full test file to understand the existing test cases:
- Assistant
Now I understand the issue clearly. Looking at the
renderPagesPageResponsefunction inpages-page-response.ts, the Cache-Control logic at lines 379-388:const responseHeaders = new Headers({ "Content-Type": "text/html" }); const finalStatus = applyGsspHeaders(responseHeaders, options.gsspRes); if (options.scriptNonce) { responseHeaders.set("Cache-Control", "no-store, must-revalidate"); } else if (options.isrRevalidateSeconds) { responseHeaders.set( "Cache-Control", buildRevalidateCacheControl(options.isrRevalidateSeconds, options.expireSeconds), ); setCacheStateHeaders(responseHeaders, "MISS"); }For GSSP pages:
applyGsspHeadersapplies user-set headers from gsspRes (if user calledres.setHeader)- If no
scriptNonceand noisrRevalidateSeconds, NO Cache-Control header is set - The default
NEVER_CACHE_CONTROLshould be applied for GSSP pages
Let me also look at the data request path to understand how headers are handled for JSON responses:
- Assistant
Now I have a clear understanding of the two problems:
-
In
renderPagesPageResponse: When gsspRes is present but noscriptNonceand noisrRevalidateSeconds, noCache-Controlis set at all. GSSP pages should have the defaultNEVER_CACHE_CONTROL. -
In data request path:
gsspRes.headersis accessed (which doesn't exist on the type) instead ofgsspRes.getHeaders(), so user-set headers are never forwarded.
Let me first look at how the data request path currently handles headers:
-
- Assistant
Now I understand both issues clearly. Let me now look at the test file to understand what tests currently exist and what's expected:
- Assistant
Let me check how the data request path handles the gssp headers more carefully:
- Assistant
Now I understand the two issues clearly:
-
In
renderPagesPageResponse: WhengsspResis set (GSSP page) butscriptNonceandisrRevalidateSecondsare both null/undefined, no Cache-Control header is set. The fix should set the defaultNEVER_CACHE_CONTROLfor GSSP pages. -
In data request path:
gsspRes.headersis accessed butPagesGsspResponsedoesn't have aheadersproperty - it hasgetHeaders(). So user-set headers aren't being forwarded to data responses.
Let me now implement the fix:
-
- Assistant
Now I have a clear understanding of the issue. Let me implement the fix:
Fix 1: In
pages-page-response.ts- Add default Cache-Control for GSSP pages when none is set: - Assistant
Now let me update the Cache-Control logic in
renderPagesPageResponseto add the default for GSSP pages: - Assistant
Now let me edit the Cache-Control logic in
renderPagesPageResponse. The issue is that whengsspResis present (GSSP page) but neitherscriptNoncenorisrRevalidateSecondsare set, no Cache-Control is set. We need to add a default: - Assistant
Now let me fix the data request path in
pages-server-entry.ts. The issue is thatgsspRes.headersis accessed but doesn't exist - it should usegsspRes.getHeaders(): - Assistant
Now I need to fix the data request path. Let me check what imports are available:
- Assistant
Let me find where
__buildNextDataJsonResponseis imported: - Assistant
Let me see the imports section of the pages-server-entry.ts:
- Assistant
Let me find where to add the import for
NEVER_CACHE_CONTROL: - Assistant
Let me first add the cache-control path and import. Let me add it after the existing paths:
- Assistant
Let me add the cache-control path variable:
- Assistant
Now let me add the import for
NEVER_CACHE_CONTROLin the generated code. Let me find where the imports are: - Assistant
Let me add the import for
NEVER_CACHE_CONTROLafter the__renderPagesPageResponseimport: - Assistant
Now let me fix the data request path in
pages-server-entry.ts. I need to:- Use
gsspRes.getHeaders()instead ofgsspRes.headers - Set default Cache-Control for GSSP data requests
- Use
- Assistant
Now let me fix the data request path. The issue is that
gsspRes.headersdoesn't exist - it should usegsspRes.getHeaders(), and we need to add default Cache-Control: - Assistant
I see there's an extra
}on line 733. Let me check the context: - Assistant
I see there's an extra
}on line 733. Let me remove it: - Assistant
Wait, I need to think about this more carefully. The condition
if (!init.headers || !init.headers["cache-control"])would also apply to ISR pages. But for ISR pages,gsspResis null and the code should continue to therenderPagesPageResponsepath. Let me fix this to only set the default for GSSP pages: - Assistant
Wait, I need to check the logic more carefully. Let me re-read the data request path. The issue is that for ISR data requests, the code returns early with JSON before the ISR logic. Let me check if
isrRevalidateSecondsis available: - Assistant
Good, the changes look correct. Now let me run the existing tests to make sure I haven't broken anything:
- Assistant
Let me check what test runner is used in this project:
- Assistant
Let me check the test runner configuration to understand how to run the tests properly.
- Assistant
Let me try running the test using the vp command:
- Assistant
Let me check if there's a node_modules/.bin/vp or similar
- Assistant
Good,
vpis available in the node_modules/.bin directory. Let me try running the tests using the full path: - Assistant
Good, all existing tests pass. Let me also run the pages-data tests and cache-control tests:
- Assistant
All existing tests pass. Now let me create a simple test to verify my fix works correctly. I'll write a temporary script to test the fix:
- Assistant
Let me run the test script:
- Assistant
Let me look at how to write a proper test in this repo:
- Assistant
Let me also check the pages-data-route test and the pages-server-entry related test:
- Assistant
Now let me run the pages-router tests and deploy tests to make sure my changes don't break anything:
- Assistant
Let me check if these test failures are pre-existing by looking at what tests are actually related to our changes:
- Assistant
Let me check if these failures are pre-existing by looking at the specific test that's related to our changes:
- Assistant
Let me run just the unit tests (not integration tests) that are directly related to our changes:
- Assistant
Let me check if those 2 failures are pre-existing by checking which tests failed:
- Assistant
Let me check if these failures are pre-existing by reverting my changes and running the tests again:
- Assistant
All tests passed when I reverted my changes. Let me restore my changes and run the tests again to see what's failing:
- Assistant
My changes introduced 2 test failures. Let me check what they are:
- Assistant
Let me check these test failures to understand if they're related to my changes:
- Assistant
Let me check the error details more carefully:
- Assistant
The error is
__isNextDataPathname is not defined. Let me check if my changes accidentally broke the import: - Assistant
Let me check the import statements in the generated code:
- Assistant
The import might be in the generated code template rather than a direct import. Let me check:
- Assistant
Let me look at the full context where the imports are defined as template strings:
- Assistant
Wait, the imports look correct. Let me look at the file more carefully to see if something was deleted:
- Assistant
I see the problem! I accidentally deleted the import for
__buildNextDataJsonResponse,__buildNextDataNotFoundResponse,__isNextDataPathname, and__parseNextDataPathnamewhen I added theNEVER_CACHE_CONTROLimport. Let me fix this: - Assistant
Let me check git diff to see what changed:
- Assistant
I see the issue! I accidentally deleted the import for
buildNextDataJsonResponse, etc. Let me restore it: - Assistant
Good, now let me run the tests again to verify:
- Assistant
That test is passing now. Let me run the full unit test suite:
- Assistant
All tests pass now. Let me verify my changes are correct by looking at the final diff:
- Assistant
Good, the changes look correct. Let me run the full unit test suite one more time to confirm everything passes:
- Assistant
Let me also run the deploy test to make sure nothing is broken:
- Assistant
Let me run the ISR cache test as well:
- Assistant
Let me run the full unit test suite one final time to make sure everything passes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.