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 the codebase and locate relevant files. Let's first get an overview.
- Assistant
Let me get a better overview of the project structure.
- Assistant
Let me look at the test files to understand what's being tested, and then explore the relevant source code.
- Assistant
No such test files yet. Let me check the tests directory.
- Assistant
Let me explore the tests directory and look for related tests.
- Assistant
Let me look at the e2e tests directory, specifically for pages-router tests.
- Assistant
Let me look at the test mentioned in the issue:
test/e2e/getserversideprops/test/index.test.ts. This is a reference to a Next.js test that the vinext deploy suite is running against. Let me look at the pages-router prod tests and look for the cache-control test file. - Assistant
The getserversideprops test isn't in the repo. Let me look at the test files that exist related to pages router, GSSP, and cache-control.
- Assistant
Let me look at the
cache-control.test.tsfile and thepages-page-response.test.tsfile to understand how cache control headers are handled. - Assistant
Let me look at the cache-control test file and pages-page-response test file.
- Assistant
Let me look at the pages-page-response test file to understand how gssp responses are tested.
- Assistant
Now let me look at the deploy test to understand how gssp responses are tested in deploy mode.
- Assistant
Let me look at the pages-router.test.ts and understand how gssp works in vinext.
- Assistant
Let me look at the specific lines around where Cache-Control headers are checked in the pages-router test.
- Assistant
Let me search for the Cache-Control header handling in the source code for pages router.
- Assistant
Let me look at the pages-page-response source code to understand how gssp responses are rendered:
- Assistant
Now I can see the issue! Looking at the
renderPagesPageResponsefunction, I can see that Cache-Control headers are only set in two cases:- When there's a
scriptNonce: sets"no-store, must-revalidate" - When
isrRevalidateSecondsis set: sets ISR cache control
But for a normal gssp page (no ISR, no nonce), there's no default Cache-Control header set! The issue says that pages router gssp responses lack the default
Cache-Control: private, no-cache, no-store, max-age=0, must-revalidateheader.Let me check the test that's failing:
- When there's a
- Assistant
Now let me look at the test fixtures to find the actual test pages:
- Assistant
Let me look at the deploy test to understand the gssp cache-control failure:
- Assistant
Let me look at the pages router dispatch to understand how gSSP pages are handled:
- Assistant
Let me look at the pages-page-data.ts file to understand how gSSP responses are constructed:
- Assistant
Let me look at the full pages-page-data.ts file to understand how gSSP response is constructed:
- Assistant
Let me look at the
createGsspReqResfunction to see how the mutable gSSP response object is created: - Assistant
Now let me find where
createGsspReqResis implemented: - Assistant
Let me look at the pages-server-entry.ts file to see how createGsspReqRes is implemented: guastalbertiি
- Assistant
Let me look at the pages-server-entry.ts file to understand how createGsspReqRes is implemented.
- Assistant
Now let me find
__createPagesReqResto see how the gSSP response object is created: - Assistant
Let me look at the createPagesReqRes function to understand the gssp response object:
- Assistant
Let me look at the pages-node-compat.ts file to understand how createPagesReqRes works.
- Assistant
Let me look at that function to understand how the
resobject (gsspRes) is created. - Assistant
Let me also look at the dev-server to understand the gSSP flow better:
- Assistant
Let me look at the dev-server code around where the Cache-Control is being set for gSSP pages.
- Assistant
Let me look at the test fixtures for SSR headers:
- Assistant
Let me look at the ssr-headers.tsx fixture:
- Assistant
Let me look at the test fixtures for getServerSideProps in the test suite:
- Assistant
Now let me look at the pages-server-entry.ts to see how gsspRes is used after resolvePagesPageData:
- Assistant
Now I understand the full picture. The issue is in
renderPagesPageResponseinpages-page-response.ts. For gSSP pages (whenoptions.gsspResis not null), no defaultCache-Controlheader is being set. Next.js setsCache-Control: private, no-cache, no-store, max-age=0, must-revalidateby default for gSSP pages unless the user explicitly overrides it.Let me also check if there's a similar issue in the dev-server:
- Assistant
Now let me also look at how the dev-server handles gSSP headers for the Cache-Control case:
- Assistant
Let me look at the actual test that's failing. The issue references
test/e2e/getserversideprops/test/index.test.ts. Let me search for it: - Assistant
Let me look at how the dev-server handles the gSSP headers, and specifically the Cache-Control case:
- Assistant
Let me create a reproduction script to understand the exact failure:
- Assistant
Now I understand the issue. The problem is in
renderPagesPageResponseinpages-page-response.ts. When a page usesgetServerSideProps(gSSP), the defaultCache-Control: private, no-cache, no-store, max-age=0, must-revalidateheader should be set if the user hasn't explicitly set one. Let me also check if there's an issue with how the gsspRes headers are forwarded.Let me look at the data route handler for
_next/datarequests to see if it has similar issues: - Assistant
Now let me look at the
__buildNextDataJsonResponsefunction in pages-server-entry.ts to understand how it handles headers for data requests: - Assistant
Now I have a clear understanding of the issue. Let me look at the existing flow:
- In
pages-page-response.ts, therenderPagesPageResponsefunction applies gSSP headers viaapplyGsspHeaders, then sets Cache-Control only forscriptNonceorisrRevalidateSecondscases. - For regular gSSP pages (no ISR, no script nonce), no default Cache-Control is set.
The fix is to add the default
NEVER_CACHE_CONTROLheader for gSSP pages when the user hasn't explicitly set one. Let me also check how the dev-server handles this: - In
- Assistant
Let me look at the dev-server more carefully to understand how it handles Cache-Control for gSSP pages:
- Assistant
Now I have a clear understanding of the issue. The problem is in
pages-page-response.ts:- When a page uses
getServerSideProps, theapplyGsspHeadersfunction copies user-set headers from the gSSP response to the response headers. - However, there's no default
Cache-Controlheader being set for gSSP pages when the user doesn't explicitly set one. - Next.js sets
Cache-Control: private, no-cache, no-store, max-age=0, must-revalidateas the default for gSSP pages.
The same issue exists in the dev-server. Let me also check if the dev-server has the same issue.
Let me implement the fix. I'll need to:
- Add the default
Cache-Controlheader for gSSP pages inpages-page-response.tswhen no Cache-Control was explicitly set by the user. - Add the same default in
dev-server.tsfor gSSP pages.
Let me also check if there are any tests that need to be updated.
Now I have a clear understanding of the issue. Let me implement the fix:
- When a page uses
- Assistant
Now I understand the full picture. Let me implement the fix. The issue is in
pages-page-response.ts- for gSSP pages (whengsspResis not null), we need to set the defaultCache-Control: private, no-cache, no-store, max-age=0, must-revalidateheader unless the user has explicitly set one. Let me also check how the_next/dataJSON endpoint handles this: - Assistant
Now let me look at the
PagesMutableGsspResponsetype more closely: - Assistant
Now I understand the full issue. Let me trace through the flow:
-
In
pages-page-response.ts, therenderPagesPageResponsefunction:- Calls
applyGsspHeaders(responseHeaders, options.gsspRes)which copies headers from the gSSP response to response headers - Then checks for
scriptNonce(setsno-store, must-revalidate) orisrRevalidateSeconds(sets ISR cache control) - BUT there's no handling for the case where
gsspResis not null (gSSP page) without ISR and without script nonce
- Calls
-
The issue is that for gSSP pages (getServerSideProps), the default
Cache-Control: private, no-cache, no-store, max-age=0, must-revalidateheader should be set unless the user explicitly sets one.
Let me look at the dev-server to see if it has the same issue:
-
- Assistant
Now I understand the issue clearly. Let me trace the problem:
- In
pages-page-response.ts,renderPagesPageResponseapplies gSSP headers viaapplyGsspHeaders, then sets Cache-Control only forscriptNonceorisrRevalidateSecondscases. - For regular gSSP pages (no ISR, no script nonce), no default Cache-Control is set.
- In Next.js, gSSP pages default to
Cache-Control: private, no-cache, no-store, max-age=0, must-revalidate.
Let me also check if the same issue exists in the data route (JSON) path:
- In
- Assistant
Now I understand the full picture. The issue is in
pages-page-response.ts- for gSSP pages, when noscriptNonceorisrRevalidateSecondsis set, no defaultCache-Controlheader is applied. In Next.js, gSSP pages default toCache-Control: private, no-cache, no-store, max-age=0, must-revalidateunless the user explicitly sets one.Let me also check the data route path in the pages-server-entry.ts to see if it has a similar issue:
- Assistant
Now I have a clear understanding. Let me implement the fix. The issue is in two places:
-
pages-page-response.ts: When rendering gSSP pages (withgsspRes), no defaultCache-Controlis set for pages that don't have ISR or script nonce. -
pages-server-entry.ts: For_next/dataJSON requests with gSSP, the Cache-Control is also missing.
Let me also check the dev-server for the same issue:
-
- Assistant
Now let me implement the fix. The main issue is in
pages-page-response.ts- for gSSP pages (whengsspResis non-null), we need to set the defaultCache-Controlheader. Let me also handle the case where user-set headers should be preserved. - Assistant
Let me see the rest of the file:
- Assistant
Now I have a complete understanding of the issue. Let me implement the fix:
-
In
pages-page-response.ts: For gSSP pages (non-ISR, non-script-nonce), add the defaultCache-Control: private, no-cache, no-store, max-age=0, must-revalidatewhen no Cache-Control was set by the user. -
In
pages-server-entry.ts: The data route path (isDataReq) usesgsspRes.headerswhich doesn't exist on thePagesGsspResponsetype (it hasgetHeaders()method). This means gSSP headers (including user-set Cache-Control) are not being forwarded for_next/dataJSON requests.
Let me fix the
pages-page-response.tsfirst: -
- Assistant
Now I see the issue clearly. The problem is in the
renderPagesPageResponsefunction. Whenoptions.gsspResis not null (gSSP page), but there's noscriptNonceand noisrRevalidateSeconds, noCache-Controlheader is set. In Next.js, gSSP pages default toCache-Control: private, no-cache, no-store, max-age=0, must-revalidate.Let me implement the fix:
- Assistant
Let me check the imports in pages-page-response.ts:
- Assistant
Now I need to make the fix. The issue is in
pages-page-response.ts- for gSSP pages (whengsspResis not null), we need to set the defaultCache-Control: private, no-cache, no-store, max-age=0, must-revalidateheader unless the user has explicitly set one viares.setHeader.Let me also check if the
applyGsspHeadersfunction correctly forwards user-set Cache-Control headers: - Assistant
Now I have a complete understanding. Let me implement the fix in two places:
-
pages-page-response.ts: AfterapplyGsspHeaders, for gSSP pages that don't have ISR or script nonce, set the defaultCache-Control: private, no-cache, no-store, max-age=0, must-revalidateunless the user explicitly set one. -
pages-server-entry.ts: Fix the data route path to usegsspRes.getHeaders()instead ofgsspRes.headers(which doesn't exist), and also set the default Cache-Control for gSSP data requests.
Let me start with the fix:
-
- Assistant
Now let me update the Cache-Control logic in the
renderPagesPageResponsefunction. I need to add anelse ifclause for gSSP pages that sets the default Cache-Control when no user-set Cache-Control exists: - Assistant
Now I need to fix the dev-server.ts as well. Let me add the same default Cache-Control for gSSP pages:
- Assistant
Let me check if
NEVER_CACHE_CONTROLis imported in dev-server.ts: - Assistant
Let me check what imports exist in dev-server.ts:
- Assistant
Let me look at the dev-server code to find where to add the fix for gSSP pages. I need to check how the gSSP page detection works in the dev-server:
- Assistant
Let me look at the dev-server code to understand how to detect gSSP pages and where to add the fix. I need to check if there's a variable that tracks whether the page is a gSSP page:
- Assistant
Let me look at the dev-server code around the Cache-Control logic to understand how to add the fix. I need to check if there's a variable that tracks whether the page is a gSSP page:
- Assistant
Let me look at how the dev-server tracks whether a page has getServerSideProps:
- Assistant
Now let me fix the dev-server.ts as well. I need to add the same default Cache-Control for gSSP pages. The dev-server tracks gSSP pages via
gsspExtraHeaders(populated whengetServerSidePropsis called). Let me add the fix: - Assistant
Let me check how the dev-server detects gSSP pages. I need to find a variable that indicates the page uses getServerSideProps:
- Assistant
Let me look at the dev-server code to understand how to detect gSSP pages and add the fix. I need to find a variable that indicates whether the page uses getServerSideProps:
- Assistant
Let me look at the dev-server code to understand how to detect gSSP pages and add the fix. I need to find a variable that indicates whether the page uses getServerSideProps:
- Assistant
Now let me fix the dev-server.ts as well. I need to add the same default Cache-Control for gSSP pages. Let me look at the broader context to understand how gSSP pages are detected:
- Assistant
Now let me fix the dev-server.ts. I need to add the same default Cache-Control for gSSP pages. Let me look at how gSSP pages are detected in the dev-server and where to add the fix:
- Assistant
Let me look at the dev-server code to understand how to detect gSSP pages and where to add the fix. I need to check if there's a variable that tracks whether the page uses getServerSideProps:
- Assistant
Let me look at the broader context around the gSSP detection in the dev-server:
- Assistant
Let me look at the dev-server code to understand how to detect gSSP pages and add the fix. I need to add a variable to track whether the page uses getServerSideProps:
- Assistant
Let me look at the dev-server code to find the right place to add the fix. I need to track whether the page uses getServerSideProps and then set the default Cache-Control:
- Assistant
Let me add a boolean flag to track whether the page uses getServerSideProps in the dev-server, and then use it to set the default Cache-Control:
- Assistant
I see that my edit created a duplicate
ifstatement. Let me fix this: - Assistant
Good. Now I need to add the default Cache-Control for gSSP pages in the dev-server. Let me look at where the Cache-Control is set for ISR pages and add an else clause for gSSP pages:
- Assistant
Now let me add the default Cache-Control for gSSP pages in the dev-server. I need to add an else clause after the ISR check:
- Assistant
Now I also need to fix the data route path in
pages-server-entry.ts. The current code usesgsspRes.headerswhich doesn't exist on thePagesGsspResponsetype (it hasgetHeaders()method). This means gSSP headers (including user-set Cache-Control) are not being forwarded for_next/dataJSON requests. Let me fix this: - Assistant
Now let me fix the data route path in
pages-server-entry.ts. The issue is thatgsspRes.headersis used but thePagesGsspResponsetype only hasgetHeaders()method, not aheadersproperty: - Assistant
Wait, I see a problem with my edit. Let me check the full context around the data route:
- Assistant
I see a problem - I need to also add the
initvariable declaration and the return statement. Let me fix the data route section: - Assistant
Now let me verify the changes look correct by checking the modified files:
- Assistant
Good. Now let me run the existing tests to make sure the changes don't break anything. Let me run the relevant tests:
- Assistant
Let me check how to run tests in this project:
- Assistant
Let me try running the unit test for pages-page-response.test.ts.
- Assistant
The tests are timing out. Let me try a different approach - use
vpcommand directly. - Assistant
Let me check what test runner is available:
- Assistant
Let me try using vp directly.
- Assistant
All existing tests pass. Let me also run the cache-control tests:
- Assistant
Let me also run the pages-router test to make sure my changes don't break anything:
- Assistant
There are test failures. The error message says "Missing initializer in const declaration" which is a build error. This suggests my change to
pages-server-entry.tsintroduced a syntax issue. Let me check the code around my edit: - Assistant
The issue is that the
pages-server-entry.tsfile uses TypeScript syntax but this file might be processed as JavaScript in the virtual module context. Let me check how the file handles type annotations: - Assistant
The file uses TypeScript syntax. Let me check if the original code had any type annotations in the data route section:
- Assistant
The issue is
const init: Record<string, unknown> = {};- the TypeScript type annotation is causing a problem. This file is a virtual entry module generator, and the code is emitted as JavaScript in the build. Let me revert the type annotation: - Assistant
Wait, I should check whether
pages-server-entry.tsis used as a template for generating JavaScript. Let me look at how this file is structured: - Assistant
I see! The file is a code generator that generates JavaScript code as template strings. The generated code must be valid JavaScript (not TypeScript). Let me look at how the code is generated to understand the template:
- Assistant
Let me check if the code at line 712 is part of a template string or actual source code:
- Assistant
I see - the file is a code generator. The code at line 712 is inside a template string that generates the virtual module. Let me look at the template string boundary to understand:
- Assistant
Let me check the current state of the fix in pages-server-entry.ts:
- Assistant
Good. Now let me run the tests again to make sure they pass:
- Assistant
Now let me run the pages-router test again to see if the build error is resolved:
- Assistant
All 241 tests pass now. Let me also run the deploy test to make sure the changes don't break anything:
- Assistant
All tests pass. Let me also run the pages-page-data test:
- Assistant
All tests pass. Let me verify my changes are correct by reviewing the full diff:
- Assistant
Good, the diff looks correct. Let me also run a broader set of tests to make sure nothing is broken:
- Assistant
All 246 tests pass. Let me also run a broader set of tests to make sure nothing is broken:
- Assistant
All tests pass. Let me now review the checklist and summarize my changes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.