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.
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 call ) 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
Let me start by exploring the repository structure to understand what we're working with.
Assistant
Now let me look at the relevant tests and how Next.js handles this:
Assistant
Now let me look at how deploy mode and gssp work together:
Assistant
Now let me look at the deploy suite tests and understand what is expected:
Assistant
Let me look at the deploy-mode entry to understand the issue:
Assistant
Let me look at the prod-server entry to understand the deploy path:
Assistant
Now let me look at what deploy mode does - the relevant worker entry:
Assistant
let me check what Next.js does for the default gSSP cache-control:
Assistant
Now I have a clear understanding. Let me look at the
renderPagesPageResponsefunction to understand the issue:Assistant
me check how
__createPagesReqResworks to understand the gSSP response shape:Assistant
me look at the tests to see how they cover gSSP:
Assistant
Now let me check the Next.js Deploy Suite test that is being used as the source for these failures:
Assistant
Now let me write a quick reproduction script to confirm the issue:
Assistant
Let me write a reproduction script to confirm the issue:
Assistant
Now let me look at the relevant Next.js source code to understand the expected behavior:
Assistant
Now let me look at how Next.js handles this in pages router specifically:
Assistant
Now I see exactly how Next.js handles this in the
pages-handler.js. Let me focus on the key part:jslet cacheControl; if (!hasStaticProps || isIsrFallback) { if (!res.getHeader('Cache-Control')) { cacheControl = { revalidate: 0, expire: undefined }; } } else if (is404Page) { ... } ... if (cacheControl && !res.getHeader('Cache-Control')) { res.setHeader('Cache-Control', getCacheControlHeader(cacheControl)); }So Next.js:
- If there's no staticProps (i.e., it's a gSSP page or isrFallback) AND the user hasn't already set
Cache-Control, setrevalidate: 0which givesprivate, no-cache, no-store, max-age=0, must-revalidate. - The
!res.getHeader('Cache-Control')check ensures user overrides are preserved.
Now let me look at where the cacheControl is then actually applied to sendPayload
- If there's no staticProps (i.e., it's a gSSP page or isrFallback) AND the user hasn't already set
Assistant
Now let me check the actual relevant deploy test file path that's being referenced:
Assistant
Let me look at the actual deploy suite (which is the cloudflare-pages-router) tests for gSSP:
Assistant
Now let me write a quick reproduction script that uses the source code directly:
Assistant
Let me write a temporary test to reproduce the issue:
Assistant
I have successfully reproduced the issue. Now let me apply the fix. Looking at the code:
- Test 1 (default gSSP page): FAILS -
Cache-Controlisnullinstead ofprivate, no-cache, no-store, max-age=0, must-revalidate - Test 2 (user sets
Cache-Control): PASSES (because the existingapplyGsspHeadersfunction does preserve it)
Let me now apply the fix to
pages-page-response.ts:- Test 1 (default gSSP page): FAILS -
Assistant
Now let me apply the fix. The logic should be:
- After applying gSSP headers (which may include user-set
Cache-Control) - If
scriptNonce, override tono-store, must-revalidate(since nonce-bearing pages are dynamic and shouldn't be cached) - If
isrRevalidateSeconds(i.e., page has getStaticProps with revalidate), set ISR cache-control - Otherwise, for gSSP pages, default to
NEVER_CACHE_CONTROL(private, no-cache, no-store, max-age=0, must-revalidate)
- After applying gSSP headers (which may include user-set
Assistant
I need to apply the fix to the source code. Let me do this with the edit tool.
Assistant
Now let me apply the fix to the cache-control logic:
Assistant
Let me use sed instead:
Assistant
me verify the fix with the reproduction test:
Assistant
Both tests now pass. Let me also check the existing test to make sure I didn't break anything:
Assistant
All existing tests pass. Now let me check the dev-server path to see if it has the same issue:
Assistant
me check the prod-server path for completeness:
Assistant
The prod-server delegates to
renderPage, which is the generated entry function. So our fix inpages-page-response.tsshould apply.Now let me check the dev-server path and see if it should also have the same fix applied (for consistency):
Assistant
me look at
streamPageToResponseto see how the dev server writes the response:Assistant
Now let me rebuild the dist file so my fix gets reflected:
Assistant
Let me update the dist file as well since some tests may use it:
Assistant
need to fix the order of conditions in the dist file:
Assistant
Now let me run the existing tests to make sure I didn't break anything:
Assistant
Now let me also run the cache-control tests:
Assistant
Let me run the reproduction test once more to verify everything works:
Assistant
Let me also test more edge cases:
Assistant
All 7 edge cases pass. Now let me also run the existing pages-router tests to make sure I haven't broken anything else:
Assistant
Let me also check the tests for cache-headers:
Assistant
Let me clean up the reproduction test now:
Assistant
Let me now think about edge cases more deeply. Let me look at the actual fixture for ssr-headers.tsx to see what it does:
Assistant
me also check the deploy mode test fixture for the relevant page:
Assistant
Let me also check the dev-server path. Although the issue is about deploy mode, the dev-server has the same bug and should be fixed for consistency:
Assistant
Now let me verify the dist file change is correct:
Assistant
Let me check if the build script regenerates the dist from source:
Assistant
The build is too slow. Let me verify my fix works on the dist file by checking the test that imports from dist:
Assistant
Let me also verify case-insensitive handling is correct:
Assistant
Case-insensitivity works correctly. Let me also verify the existing tests still pass:
Assistant
Let me also run the broader test suite to make sure nothing else broke:
Assistant
The unit test project excludes the integration tests. Let me look for unit tests that may be relevant:
Assistant
All tests pass. Let me also run the prerender and build tests:
Assistant
All prerender tests pass. Now let me also run a quick test to verify the dist file change is correctly working with the source:
Assistant
Both dist file tests pass. Let me also clean up:
Assistant
Good, all temporary files are cleaned. Let me also run a broader test to confirm I haven't broken anything important:
Assistant
All 50 tests pass. Let me also verify the source code change is complete and clean:
Assistant
Interesting - the dist file changes don't show up in git status. That's because the dist file might be gitignored or not tracked. Let me check
Assistant
Yes,
dist/is gitignored. So my changes to the dist file won't be in the diff. That's fine - the source change is what matters.But wait, if the dist file is gitignored, then it won't be committed when I submit. So my dist file changes will not be submitted. Let me check if this is a problem.
Actually, since the tests import from
packages/vinext/src/, not frompackages/vinext/dist/, the source change is what matters for the tests. The dist file is regenerated by the build script.However, for the actual deploy, the dist file is what's used. So the deploy tests would need the dist file to have my changes. Let me check how this works.
Actually, looking at the package.json:
code"build": "vp pack"And vp pack builds the dist file. So when the user runs
vinext deploy, it should run the build step which regenerates the dist file from source.Looking at the deploy.ts file:
- The user runs
vinext deploy - It runs the build step (
pnpm run buildor similar) - This regenerates the dist file
- Then deploys
- The user runs
Assistant
dist file is generated by the build script. My source change is sufficient. Let me verify by checking how the deploy workflow uses these files:
Assistant
Let me also check the data route handler (for
_next/dataJSON envelope):Assistant
Let me also check and fix the data route handler:
Assistant
Let me also check the pages-data-url tests:
Assistant
me also fix the data route handler for the JSON envelope to apply the default Cache-Control:
Assistant
me update the data route handler to apply the default Cache-Control for gSSP pages:
Assistant
let me add the import path and update the data route handler:
Assistant
The issue is that the dollar sign in
${JSON.stringify(...)}is being interpreted as a template literal variable. Let me use a different approach to avoidAssistant
Let me verify the changes:
Assistant
a syntax error - the braces are wrong. Let me fix this:
Assistant
Now let me verify the syntax is correct:
Assistant
Now let me write a test for the data route handler to verify it works correctly:
Assistant
The TypeScript source can't be loaded directly by Node. Let me write a unit test using the test framework instead:Let me write a unit test using the test framework instead:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[cd /vinext && rm -f /tmp/test-data-route.mjs && rm -f /tmp/patch-data-route.mjs]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
Let me make a tool
Assistant
Let me check the pages-page-data tests more:
Assistant
Let me run the tests to verify nothing is broken:
Assistant
Let me also verify the dist file changes are correct:
Assistant
Now let me also run a broader test suite to make sure nothing is broken:
Assistant
There's a syntax error - backticks in comments are being interpreted. Let me fix:
Assistant
Wait, this comment doesn't have template literal issues. The error was different. Let me re-read the error message:
code[38;5;249m/Assistant
error message was truncated. Let me re-run to see the full error.
Assistant
I see the issue - the backticks in the comment are interfering. The issue is that within a string template literal in TypeScript, the backticks need to be escaped. Let me check the file at that location:
The file is generated as part of a template literal in
pages-server-entry.ts. So the entire content is inside a template literal\...`. Within this template literal, backticks in comments need to be escaped with\``.Let me look at the surrounding
Assistant
Yes, I can see that the content is generated inside a template literal
return \...``. So any backticks in the content need to be escaped. Let me check the original comment to see what escaping is used elsewhereAssistant
The content is inside a template literal. I need to remove the backticks from my comment:
Assistant
Now let me verify the change is correct:
Assistant
Let me run a broader test suite:
Assistant
All 75 tests pass. Now let me also verify the dist file change works for the data route:
Assistant
Let me run the existing tests one more time to confirm:
Assistant
Let me also write a test for the data route handler. Let me look at the test for buildNextDataJsonResponse:
Assistant
Let me also write a test for the data route fix:
Assistant
function is in a different file. Let me fix the import:
Assistant
Now let me clean up:
Assistant
Let me also run a broader test to make sure all my changes are good:
Assistant
All 94 tests pass. Let me now also verify the deploy test:
Assistant
Let me also run the deploy test to verify my dist file changes don't break anything:
Assistant
Let me also check the deploy test:
Assistant
All 229 tests pass. Let me also verify by looking at the diff:
Assistant
Let me also do a broader sanity check by running all the unit tests:
Assistant
Excellent! All 4755 unit tests pass! Let me now also verify my changes work with the dist file:
Assistant
me also do a final verification by running the relevant tests:
Assistant
All 108 relevant tests pass. Let me also run a few more relevant tests:
Assistant
Now let me verify the final summary of my changes:
Assistant
Let me do a final verification by viewing the complete diff:
Assistant
Let me also verify the dist file is updated to be consistent (although it's gitignored, this ensures deploy mode works):
Assistant
Now let me run a final comprehensive test:
Assistant
All 125 tests pass. Let me also think about whether there's a
getStaticPropscase I need to handle:Looking back at the issue:
Tests expect the default
private, no-cache, no-store, max-age=0, must-revalidatefor gssp pagesThe issue is specifically about gSSP pages. Let me verify by looking at the test path mentioned:
test/e2e/getserversideprops/test/index.test.ts. This is about getServerSideProps specifically.Let me verify that the fix works for both the HTML response and the JSON data response by looking at the deploy path one more time:
Assistant
Let me do one more final verification:
Assistant
Now let me also do a sanity check on the
dist/file (even though it's gitignored, it might be needed for the deploy tests):
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.