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
Let me start by exploring the repository structure to understand what we're working with. This appears to be a vinext (Vercel/Cloudflare Next.js) project, and the issue is about missing Cache-Control headers for Pages Router gssp (getServerSideProps) responses.
Assistant
Let me explore the structure more, particularly looking at the vinext package and its source files.
Assistant
Let me look at the structure more carefully. This is the vinext repository. Let me look at the source files in the packages directory and especially focus on Pages Router and gssp-related code.
Assistant
<tool_call> <function=bash_terminal> <parameter=command> ls -la /vinext/packages/vinext/ </tool_call> <tool_call> <function=bash_terminal> <parameter=command> find /vinext/packages/vinext -name ".ts" -path "/src/*" | head -50 </tool_call> <tool_call> <function=bash_terminal> <parameter=command> ls -la /vinext/tests/ </tool_call>
Assistant
The environment didn't return a response for my tool calls. Let me try again with just one command.
Assistant
Good, I can see the vinext package has a
srcdirectory. Let me explore it.Assistant
Let me look at the tests directory and the gssp-related test file mentioned in the issue, as well as the server-side code that handles Pages Router getServerSideProps (gssp).
Assistant
Let me look at the existing test file for cache-control and the e2e/getserversideprops test directory mentioned in the issue.
Assistant
Let me look at the e2e folder structure and the getserversideprops test.
Assistant
The issue mentions
test/e2e/getserversideprops/test/index.test.tsbut that seems to be from the Next.js deploy suite, not from the vinext repo itself. Let me look at the pages-router related tests in the vinext repo.Assistant
Let me look at the pages-router-prod test directory and also look at the source code that handles pages-router gssp responses.
Assistant
Let me focus on finding the code that handles Pages Router gssp (getServerSideProps) responses. The issue says:
- Default
Cache-Controlheader is not applied for gssp pages - User
setHeadercalls are dropped
I should look at:
- The server-side code that handles pages router responses
- The pages-node-compat.ts or similar files
- Any files related to page response handling
Let me look at the pages-router related source files.
- Default
Assistant
Let me look at the key files for Pages Router gssp handling:
Assistant
Now I understand the issue. Looking at
pages-page-response.ts:applyGsspHeadersapplies the gssp response headers (including user-set ones) to the response- But then, the code sets
Cache-Controlbased only onscriptNonceandisrRevalidateSecondsconditions - For non-scriptNonce, non-ISR gssp pages, no Cache-Control header is set at all
Let me look at more context to understand the full flow:
Assistant
Now let me understand how the
resobject works and how headers are set in gssp:Assistant
Let me look at the request pipeline to understand how gssp responses are served:
Assistant
Let me look at where
renderPagesPageResponseis called from:Assistant
Now let me look at the pages-server-entry.ts file to see how the pages router gssp responses are rendered:
Assistant
Assistant
Let me try the command again.
Assistant
Now let me look at the existing pages-router tests and also search for any gssp-related tests:
Assistant
So no Cache-Control tests in pages-router.test.ts. Let me search more broadly for gssp and getServerSideProps tests.
Assistant
Let me look at the test for "getServerSideProps headers and status are applied to the response" to understand the pattern:
Assistant
Let me look at the test fixture pages:
Assistant
Let me find the test fixtures directory structure.
Assistant
Let me look at the pages-basic fixture to understand how tests are structured:
Assistant
Let me look at the ssr-headers.tsx fixture page to understand the pattern:
Assistant
Now I understand the full picture. The issue is:
- In
pages-page-response.ts, therenderPagesPageResponsefunction handles gssp responses applyGsspHeaderscopies headers fromgsspRes(the user-set headers viares.setHeader) to the response headers- But then, for non-scriptNonce, non-ISR pages, no Cache-Control header is set at all
- The fix: when there's a gsspRes and no Cache-Control was already set (by user or ISR/scriptNonce), we should set the default
Cache-Control: private, no-cache, no-store, max-age=0, must-revalidate
Let me also check if there are any tests that might already assert the Cache-Control header. Let me look for the
ssr.tsxpage fixture to see if it tests default headers.- In
Assistant
Now I have a clear understanding. Let me first reproduce the bug by checking the current behavior, then fix it.
Assistant
Let me create a test script to reproduce the issue:
Assistant
Now let me verify the current behavior and understand the exact fix needed. Let me look at the
pages-page-response.tsfile again focusing on the exact location where Cache-Control should be set:Assistant
Now I understand the full picture. Let me look at the exact section of
renderPagesPageResponsethat needs to be fixed:Assistant
Now I have a clear understanding of the issue. Let me implement the fix.
The problem is in
renderPagesPageResponsein/vinext/packages/vinext/src/server/pages-page-response.ts. When there's a gssp page (indicated byoptions.gsspResbeing non-null) but noscriptNonceand noisrRevalidateSeconds, noCache-Controlheader is set at all. The fix is to add anelse ifclause that sets the default gsspCache-Controlwhen:gsspResexists (it's a gssp page)- No
Cache-Controlheader was already set by the user viares.setHeader(which would have been applied viaapplyGsspHeaders)
Assistant
Now I'll implement the fix. The issue is that for gssp pages (those with
getServerSideProps), noCache-Controlheader is being set unless the user explicitly sets one. The fix is to add the default gsspCache-ControlwhengsspResis non-null and noCache-Controlwas already set by the user.Assistant
Now I'll implement the fix. The issue is that when there's a gsspRes (indicating a
getServerSidePropspage) but noscriptNonceand noisrRevalidateSeconds, noCache-Controlheader is set. I need to add an else-if clause that sets the default gsspCache-ControlwhengsspResexists and no Cache-Control was already set.Assistant
Let me use the correct edit syntax:
Assistant
Let me use the replace command with heredoc syntax:
Assistant
Let me use sed to make the replacement:
Assistant
I need to add an else-if clause after line 387 to set the default Cache-Control for gssp pages. Let me use the edit command properly.
Assistant
Let me use sed to insert the new lines:
Assistant
Let me use sed to insert the new code after line 387:
Assistant
Let me check the result of the sed edit.
Assistant
The sed command messed up the code structure. Let me revert and fix it properly.
Assistant
Good, reverted. Let me use Python to make the edit precisely:
Assistant
Python3 is not available. Let me try using node.js instead since this is a JavaScript/TypeScript project.
Assistant
Let me verify the changes were made correctly:
Assistant
The edit got corrupted - the
else ifclause wasn't inserted correctly. Let me revert and fix it properly.Assistant
Let me look at the exact file content again and be very careful with the edit.
Assistant
Let me use a safer approach with node and avoid bash history expansion issues by using single quotes and escaping properly.
Assistant
Let me verify the changes:
Assistant
The changes look correct. Now let me verify the fix works by running the relevant tests. Let me first check if there's a build step required and then run the pages-router tests.
Assistant
Let me run the pages-router tests to verify the fix doesn't break anything:
Assistant
Let me try using pnpm to run the tests instead:
Assistant
Let me check what test runner is available and try a more direct approach:
Assistant
The terminal timed out. Let me check if pnpm is working properly. The previous command timed out while trying to download pnpm. Let me try running tests with the already available pnpm binary.
Assistant
The corepack is asking for confirmation. Let me skip it:
Assistant
The pnpm/corepack is prompting for confirmation. Let me check if there's a way to bypass this or find an existing built version.
Assistant
Good, there's a compiled version in dist. Let me check if I need to update the dist file too:
Assistant
Let me look at the dist file to understand its structure and update it to match:
Assistant
I need to update the dist file too since it's the compiled version. Let me check the source changes first:
Assistant
Now let me update the dist file to match the source changes:
Assistant
Let me verify the dist file was updated correctly:
Assistant
Let me check if there are other copies of this file in the dist directory:
Assistant
Good, there's only one copy. Now let me also check if there are any standalone build copies:
Assistant
Let me verify the git diff to see exactly what changes were made:
Assistant
The source file changes look good. Now let me also check the dist file changes and verify they match:
Assistant
Let me check if the dist file change is being tracked by git. The dist files might not be in git. Let me verify the dist file change is correct.
Assistant
I notice the dist file change isn't tracked by git (it might be in .gitignore). Let me verify the dist file has been updated correctly and then try to run some tests. Let me also check if the dist file is actually needed or if the source is built at runtime:
Assistant
Good, the dist folder is gitignored, but the dist files are needed for the build to work. Let me verify the dist file change is correct:
Assistant
The dist file is also correctly updated. Now let me try to run a quick test to validate the fix works. Let me check if there's a way to run tests without pnpm:
Assistant
Let me try to run the tests using the available test framework:
Assistant
Let me try running the tests directly with vitest:
Assistant
The test passed. Now let me verify more thoroughly by checking if the fix works for both cases:
- Default gssp pages get the Cache-Control header
- User-set Cache-Control headers are preserved
Let me run more gssp-related tests:
Assistant
All 10 gssp-related tests passed. Now let me write a more specific test to verify the Cache-Control header is being set correctly. Let me create a temporary test script to verify the behavior:
Assistant
All 20 SSR-related tests passed! Now let me verify the fix works for the specific Cache-Control case by creating a quick validation script that checks the response headers:
Assistant
The fix is verified. Let me run a broader test to make sure I haven't broken anything else:
Assistant
Let me run the full pages-router test suite to make sure everything still works:
Assistant
All 241 tests in the pages-router test suite passed. Let me also run the cache-control tests to make sure they still work:
Assistant
Excellent! All tests pass. Let me also run the pages-page-response tests:
Assistant
Let me also run the pages-page-data tests and pages-data-route tests to make sure nothing is broken:
Assistant
All tests pass. Let me verify the final state of the changes:
Assistant
The fix is complete. Let me summarize what was done:
Summary
Issue: Pages Router
getServerSideProps(gssp) responses were missing theCache-Controlheader. Tests expected the defaultprivate, no-cache, no-store, max-age=0, must-revalidatefor gssp pages and custom values set viares.setHeader('Cache-Control', ...), but vinext returnednull.Root Cause: In
/vinext/packages/vinext/src/server/pages-page-response.ts, therenderPagesPageResponsefunction only setCache-Controlheaders for:- Script nonce pages (
no-store, must-revalidate) - ISR pages with revalidation (using
buildRevalidateCacheControl)
For plain gssp pages without script nonce or ISR revalidation, no
Cache-Controlheader was being set at all.- Script nonce pages (
Assistant
Let me try the submit command without arguments.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.