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.
Interface
No new interfaces are introduced.
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 statusor 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 structure to understand the codebase.
Assistant
Let me look at the relevant files for Pages Router gssp responses. The issue mentions
getServerSideProps(gssp) responses. Let me look at pages-page-data.ts, pages-page-response.ts, pages-data-route.ts, and cache-control.ts / cache-headers.ts.Assistant
Let me look at how the gssp result is used to build the final response.
Assistant
Now I see the relevant logic. Let me search for
createGsspReqResand how gssp responses are created.Assistant
Let me look at the
buildNextDataJsonResponseandcreatePagesReqResfunctions.Assistant
Let me look at the dev-server.ts handling of gssp, since it might have the right behavior already (as a reference).
Assistant
Let me examine the
pages-node-compat.tsto understand the res object andgetHeaders.Assistant
Let me look at the test file mentioned in the issue.
Assistant
Let me check the Next.js reference for how the default gssp Cache-Control is set.
Assistant
Let me look at the prod-server.ts and how the response is handled in deploy mode.
Assistant
Let me write a reproduction script to confirm the current behavior of
renderPagesPageResponsefor a gssp page.Assistant
At the
renderPagesPageResponselevel, user-set headers are preserved but the default is missing. The issue also says user-set headers are dropped — that must happen downstream in the deploy path. Let me investigate the Cloudflare/deploy path.Assistant
The pages-server-entry.ts is the entry. The response from
renderPagesPageResponseis returned directly. Let me check if there's a request pipeline that wraps it. Let me look at the full pages-server-entry.ts structure, especially the response handling and whether middleware headers are merged afterwards.Let me look at how the pages-server-entry handles the response and whether there's post-processing. Let me look at the top of pages-server-entry.ts and the main handler.
Assistant
Now let me find where the renderPage response is post-processed (middleware header merging).
Assistant
Let me look at
mergeWebResponseto see if it strips/overrides Cache-Control.Assistant
Let me look at the deploy.ts (Cloudflare Workers path) which is what the deploy suite tests.
Assistant
Let me look at the e2e test directory to understand the deploy suite setup and find any gssp tests.
Assistant
Let me look at how Next.js sets the default gSSP Cache-Control. Let me check the nextjs-compat tests and the cache-control test.
Assistant
Let me check
getScriptNonceFromHeaderSourcesand how scriptNonce is determined.Assistant
Let me look at the fixtures to find gssp pages and understand the test setup.
Assistant
Let me check the existing tests in
pages-page-response.test.tsandpages-page-data.test.tsto understand the data path. Let me also reproduce the actual deploy behavior. Let me write a more complete reproduction that simulates the full flow including the data request path. But actually, the simplest is to write a test that uses the actual renderPage through the generated entry. That's complex.Let me think about the issue more carefully. The 2 test failures are in
test/e2e/getserversideprops/test/index.test.ts. Let me look at the Next.js test file to know exactly what's tested. Let me check if it's available somewhere or check the classify-nextjs-suites test which references it.Assistant
Let me look at the nextjs-compat tests to understand the structure of these compat tests.
Assistant
Let me look for the Next.js test reference or any cached copy to understand exact expectations.
Assistant
Let me look at how the prod-server tests are run and the helpers, to reproduce the actual flow.
Assistant
Let me look at the data request path in pages-server-entry.ts more carefully.
Assistant
Let me check the
tests/entry-templates.test.tsand similar to see how the generated entry is tested.Assistant
Let me look at the FIXTURE_DIR and what gssp pages exist there. Let me find a gssp page in the fixture used by pages-router.test.ts.
Assistant
Let me write a reproduction script that builds the fixture and uses the prod-server to fetch a gssp page's Cache-Control.
Assistant
Let me write a reproduction that does a full build + prod server and checks gssp Cache-Control.
Assistant
Good. There's already a
/ssrpage in the fixture which is a gssp page. Let me check that page.Assistant
There's an
ssr-headers.tsxpage. Let me look at it — it might set headers.Assistant
Now let me write a reproduction test that builds and starts the prod server, then checks Cache-Control on gssp pages.
Assistant
The return is
{ server, port }. Let me fix.Assistant
Let me add a temporary fixture page that sets a custom Cache-Control to test the full prod path.
Assistant
The prod Node path preserves the user override but misses the default. Let me also check the data request path (
/_next/data/...json), which usesgsspRes.headers(likely a bug).Assistant
Let me extend the repro to test the data request path too.
Assistant
The sed failed. Let me open and edit the file directly.
Assistant
No python. Let me use node.
Assistant
Let me look at the existing cache-control test and related tests to understand expectations before making changes.
Assistant
Let me check what pages exist and whether any are plain (no data fetching), and check existing test expectations for Cache-Control on those.
Assistant
Let me check lines 390-410 and 3300-3315 of pages-router.test.ts to understand the
no-store, must-revalidateexpectation.Assistant
Let me look at the pages-page-data.test.ts to understand the data path tests.
Assistant
Now I understand the structure well. Let me look at the exact lines in
pages-page-response.tsto edit.Assistant
Now let me make the edits. First, update the import to include
NEVER_CACHE_CONTROL:Assistant
Now update the Cache-Control block to add the gssp default:
Assistant
The
replacecommand requires the lines to be in the displayed window. Let me navigate to line 379 first.Assistant
Now Fix B: the data request path. Let me check whether the data request block is inside the template string in the generator file.
Assistant
The data request block is inside the generated template string (starts line 207, ends 832). Let me view it.
Assistant
I need to fix the data request block (use
getHeaders()) and apply the default. Let me check the imports section of the generated template.Assistant
Let me add a cache-control path import. First check the path definitions at the top.
Assistant
Now add the import for
NEVER_CACHE_CONTROLin the generated template imports section:Assistant
Now fix the data request block. Let me navigate to it:
Assistant
Let me check the existing tests for the data request flow and
buildNextDataJsonResponse.Assistant
Let me check if any test asserts data request status codes for gssp pages that set non-200 status.
Assistant
Now let me fix the data request block to use
getHeaders(), forward status, and apply the default Cache-Control:Assistant
Let me search the whole filesystem for the actual Next.js getserversideprops test content to understand exactly what's expected.
Assistant
I need to handle
set-cookiearrays properly in the data path. Let me enhancebuildNextDataJsonResponseto use aHeadersobject and handle array values (set-cookie). Let me view it:Assistant
Let me rewrite
buildNextDataJsonResponseto handle set-cookie arrays properly using aHeadersobject:Assistant
Now update the entry data path to keep
set-cookieas an array so the helper appends them individually:Assistant
The current open file is wrong. Let me open the entry file at the data block:
Assistant
Now let me rebuild and re-run my repro to verify the prod fix:
Assistant
The backticks in my comments break the template literal. Let me remove backticks from the comments in the generated entry:
Assistant
Let me check the original file to see how backticks in comments were handled (escaped with
\):Assistant
The original comment at line 707 used
/next/data/<buildId>/<page>.jsonWITHOUT backticks. But the current line 717 has backticks`/_next/data`— wait, that was part of the original comment? No, the original line 706 was "// For client-side navigations Next.js fetches /_next/data//.json" without backticks.But the error is at line 719. The current file line 717 has backticks
`/_next/data`. Hmm wait — did the original have backticks? The git show shows line 706 (original) has no backticks. But my current line 717 (which is the same comment line "response during getServerSideProps so the/_next/dataJSON") — wait, that's a DIFFERENT line. Let me re-read.Actually, the line 717 in current file is:
// response during getServerSideProps so the \/_next/data` JSON`. The backticks there — were they in the original? The original line 710 (git) is "cookies set on the gsspRes by getServerSideProps are forwarded so" — no backticks. Hmm, these are different comment lines. Let me re-examine.Assistant
Backticks inside the template string must be escaped. Let me replace my added comments to use single quotes instead of backticks:
Assistant
Let me re-run the repro to verify the prod fix:
Assistant
All cases now work. Let me run the existing relevant unit tests to ensure nothing breaks. First, the directly-affected ones:
Assistant
The prod fix works and existing tests pass. Now let me also fix the dev server path for consistency. Let me check the dev-server imports and the relevant blocks.
Assistant
Now let me update the dev HTML path extraHeaders block. Let me view it:
Assistant
Now let me update the dev data request path. Let me view it:
Assistant
Let me check existing dev tests that touch gssp pages and cache-control to ensure my dev change is safe:
Assistant
Let me write a dev-server repro to confirm the dev path. Let me check the
startFixtureServerhelper signature:Assistant
Dev path works too. Now let me clean up repro artifacts and run the broader test suites. First, let me remove the repro test files and temp fixture page:
Assistant
Now let me run the main pages-router test suite (dev + prod) to ensure nothing breaks:
Assistant
All 241 pass. Now let me run the deploy-related tests and other affected suites:
Assistant
All pass. Let me run the entry template and build optimization tests since I modified the generated entry:
Assistant
Let me verify no test fetches the data endpoint for the
ssr-headerspage (which sets status 201) that would now forward 201:Assistant
No test fetches the data endpoint for ssr-headers. Let me run a few more potentially-affected suites (cache-related, cloudflare, route-handler):
Assistant
Let me verify
streamPageToResponseactually writesextraHeaders(including Cache-Control) to the Node response:Assistant
streamPageToResponsewrites extraHeaders including Cache-Control. Let me run a few more build/prod-related suites to be thorough:Assistant
All pass. Let me review the full diff to ensure correctness:
Assistant
The diff is clean. Let me do a final end-to-end verification on the prod path (HTML + data) after all edits, then clean up:
Assistant
All assertions pass, including set-cookie array preservation on both HTML and data paths. Let me clean up the repro artifacts:
Assistant
The fix is complete and verified. Let me run the full unit test project to ensure no regressions from the shared helper change:
Assistant
All 4755 unit tests pass. Let me run the integration project too:
Assistant
The integration project is large and timed out, but I've already run all the key affected integration suites (pages-router, pages-i18n-prod, pages-router-concurrency, standalone-output, static-export, prerender, entry-templates) which all passed. Let me reformat one long line in the entry for readability/cleanliness:
Assistant
Let me re-run the directly-affected unit tests to confirm the reformatting didn't break anything:
Assistant
Let me verify
isFallbackRenderis in scope at both dev blocks:Assistant
The scopes are correct. Let me run a quick lint check on the changed files:
Assistant
Lint passes. Let me run the typecheck (
vp check):Assistant
Typecheck, lint, and formatting all pass. Let me do a final review of the complete diff:
Assistant
The diff is clean and complete. Let me confirm no leftover repro artifacts remain:
Assistant
All changes are clean and verified. Let me submit.
Summary
I resolved the issue where Pages Router
getServerSideProps(gssp) responses were missing the defaultCache-Controlheader and dropping user-setres.setHeader('Cache-Control', ...)overrides.Root causes
- HTML path (): For gssp pages the block only fired for CSP-nonce or ISR (revalidate) pages, so plain gssp pages got .
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.