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 the codebase.
Assistant
Let me look at the existing test infrastructure for getserversideprops.
Assistant
Let me search for the Next.js reference test to understand what they expect.
Assistant
Now let me check the actual Next.js test file the issue references:
Assistant
Now I understand the issue. Let me look at the test fixture in the Next.js repoto see what pages they use:
Assistant
Now let me look at the prod-server to understand how it handles this:
Assistant
Now let me look at the deploy mode where the issue is reported. Let me search the deploy-related code:
Assistant
Now let me look at the
pages-page-response.tsto understand the rendering:Assistant
Let me check what the test fixture has and how tests run:
Assistant
Now let me reproduce the issue. Let me first look at the actual tests for cache-control:
Assistant
Let me look at how Next.js handles this default cache-control for pages router:
Assistant
Now I see Next.js's logic. Let me look at lines around the no-cache settingmore carefully:
Assistant
Now let me look at send-payload to understand the rest:
Assistant
Let me look at where Next.js applies the default
private, no-cache, ...for gSSP pages:Assistant
Now let me look at what cacheControl would be for getServerSideProps. Let me check how Next.js sets upthe cacheControl for gssp pages.
Assistant
I see. So in Next.js:
- If the page has only
getServerSideProps(nogetStaticProps), and no user-setCache-Control, it setscacheControl = { revalidate: 0, expire: undefined }. - Then in
sendRenderResult, ifcacheControl && !res.getHeader('Cache-Control'), it callsres.setHeader('Cache-Control', getCacheControlHeader(cacheControl)). getCacheControlHeader({ revalidate: 0, expire: undefined })returns .
- If the page has only
Assistant
Now let me write a reproduction test script to verify the bug:
Assistant
Let me check the actual response the dev-server sends. Let me also write a reproduction test:
Assistant
Let me look at
streamPageToResponseto see what it does with extraHeaders:Assistant
Let me actually run a test to see if the current dev mode preserves the Cache-Control:
Assistant
I've confirmed the first issue. Let me now add a test page that sets Cache-Control:
Assistant
Now let me check the prod path. Let me look at the unit tests for
pages-page-response:Assistant
Let me write a unit test to confirm the prod path also has the bug:
Assistant
Let me look at how gsspRes is created in deploy mode:
Assistant
Let me find the
__createPagesReqResfunction:Assistant
Let me look at the cloudflare worker entry:
Assistant
Now let me look at the next part of the code to understand the full data flow:
Assistant
Let me look at the structure of
gsspResto see how headers are exposed:Assistant
Let me look at how
PagesGsspResponseis defined:Assistant
Found a potential bug! In the deploy entry, the code does
gsspRes.headersbut the type definition isgsspRes.getHeaders(). SogsspRes.headersdoesn't exist on the typed response.Wait, let me check again. The type says
getHeadersis a function. But the code accessesgsspRes.headers. So either:- The runtime object has
.headers(maybe from the PagesMutableGsspResponse type) - This is buggy code accessing a non-existent field.
Let me check the
PagesMutableGsspResponsetype:- The runtime object has
Assistant
Found a critical bug! In the deploy entry, the code does
gsspRes.headersbutgsspResonly hasgetHeaders()method. So in deploy mode, when handling data requests (/_next/data/...), the user-set headers are NOT forwarded.Let me also check the data request handler in dev mode:
Assistant
Let me also check the data path more carefully. First, let me look at the build/prod mode for the data path:
Assistant
Now let me set up the fix. I'll need to:
- Modify
pages-page-response.ts(prod path) to set defaultCache-Controlfor gSSP pages - Modify
dev-server.ts(dev path) to set defaultCache-Controlfor gSSP pages - Fix the bug in
pages-server-entry.tswheregsspRes.headersshould begsspRes.getHeaders()
Let me first look at the gSSP type and where the fix should go:
- Modify
Assistant
Now let me look at where the headers are set after
applyGsspHeaders:Assistant
Now let me look at where the cache-control constant lives so I can reuse it:
Assistant
Now let me apply the fix to
pages-page-response.ts:Assistant
Now let me apply the fix to set the default Cache-Control for gSSP pages:
Assistant
Now let me run the test to verify the fix works for the prod path:
Assistant
The prod path now sets the default. Now let me apply the fix to the dev path:
Assistant
Now let me add the import for
NEVER_CACHE_CONTROL:Assistant
Now let me find and update the dev-server logic to apply the default
Cache-Controlfor gSSP pages:Assistant
Now I need to update the dev-server to track whether gSSP was called and apply the default
Cache-Control:Assistant
Let me update the dev-server to track whether gSSP was actually called:
Assistant
Now let me update the
extraHeadersblock to apply the defaultCache-Control:Assistant
Now let me also fix the data request path in dev-server.ts. Let me look at the data request handling:
Assistant
Now let me update the data request handler to apply the default
Cache-Control:Assistant
Now let me run the dev test to verify the fix works:
Assistant
The default Cache-Control is now being set in dev mode. Now let me fix the deploy mode data path bug (
gsspRes.headers→gsspRes.getHeaders()):Assistant
Now I need to make sure
NEVER_CACHE_CONTROLis imported inpages-server-entry.ts:Assistant
Let me add the import for
NEVER_CACHE_CONTROL:Assistant
Now I need to add the import statement for
NEVER_CACHE_CONTROL:Assistant
Let me check the
__buildNextDataJsonResponsefunction signature:Assistant
Let me look at the issue more carefully. The
init.headersis treated as a Record, so I need to convert Headers instance to a plain object:Assistant
Let me refactor my fix to convert Headers instance back to a plain object:
Assistant
Let me refactor
buildNextDataJsonResponseto properly handle aHeadersinstance:Assistant
Now let me also clean up the caller code to be more readable. Let me update the
pages-server-entry.tsto make it cleaner:Assistant
Now let me run the tests to make sure my changes don't break anything:
Assistant
Now let me also test the data path explicitly with
buildNextDataJsonResponse:Assistant
Now let me run the existing tests to make sure nothing is broken:
Assistant
Let me look at line 714 to see the issue:
Assistant
I see the issue. The template literal in the comment contains backticks which interferes with the template literal in which this comment is embedded. Let me look at the actual generated content. Let me search for backticks in this file:
Assistant
Let me fix the comment by escaping the backticks:
Assistant
Let me run the pages-router test again:
Assistant
All 241 tests pass. Let me also check the cache-control test:
Assistant
Now let me also look at the dev-server to make sure my fix doesn't break anything. Let me also clean up my test files:
Assistant
Now let me write a more comprehensive end-to-end test to verify the fix works for both the HTML and data paths:
Assistant
Let me look at the ssr-res-end.tsx:
Assistant
The
/ssr-res-endcase short-circuits viares.end(), so the response is already sent and we can't add a default. That's fine - users can set Cache-Control themselves in that case. Let me update my test:Assistant
Now let me also create a page with user-set Cache-Control to verify the override is preserved in dev mode:
Assistant
Now let me also test the prod path by looking at the existing test infrastructure:
Assistant
Let me run the ISR tests:
Assistant
Now let me also check the deploy test to make sure I haven't broken anything:
Assistant
Let me also run the build tests:
Assistant
Let me clean up the test files:
Assistant
Let me check the changes I made:
Assistant
Let me verify what happens when middleware sets a Cache-Control header:
Assistant
Let me check how middleware headers are merged:
Assistant
Let me check
mergeResponseHeaders:Assistant
Let me look at how the prod-server handles this. Let me also check if middleware is even set in the failing test scenario:
Assistant
Let me check if there's any test that checks middleware-set Cache-Control interaction:
Assistant
Let me check how the deploy worker handles response headers:
Assistant
Let me check how the deploy entry sends responses:
Assistant
So
mergeWebResponseis only in prod-server.ts. It's used in the prod-server (Node.js server). The deploy entry uses a separate worker that doesn't go through prod-server.Wait, the deploy mode is when the user runs
vinext deploy. Let me check how the deploy entrycreates the worker:Assistant
Let me look at the Cloudflare worker entry:
Assistant
Let me look at how
res.getHeaderworks in dev mode and refine my fix:Assistant
Let me update my dev-server fix to also respect middleware-set Cache-Control:
Assistant
Let me also update the data path in dev-server to be similarly defensive:
Assistant
Let me run the tests again to make sure everything still works:
Assistant
Let me check how
__vinextStreamedHtmlResponseis used in the merge step:Assistant
Let me focus on the failing test scenarios and verify my fix works. Let me also write a more comprehensive integration test:
Assistant
All three test scenarios pass in dev mode. Let me also test the data request path manually:
Assistant
Let me check how data requests are detected:
Assistant
Let me check how the data request header is handled:
Assistant
Let me check the existing pages-data tests to understand how data requests work:
Assistant
Now I can write a proper test using the
/_next/data/...URL pattern:Assistant
All 5 tests pass! Both HTML and data paths work correctly:
- Default
private, no-cache, no-store, max-age=0, must-revalidatefor gSSP pages - User-set Cache-Control via
res.setHeaderis preserved - Data requests (
/_next/data/...) also work correctly
Let me clean up the test files now:
- Default
Assistant
Now let me also think about the prod path more carefully. Looking at my changes in
pages-page-response.ts:Assistant
Let me update the comment in
pages-page-response.tsto be more accurate:Assistant
Let me simplify the comment:
Assistant
Now let me run all the tests to verify everything works:
Assistant
All 241 tests pass. Let me also run the deploy and build tests:
Assistant
All 308 tests pass. Now let me also make sure the changes are complete by reviewing the diff:
Assistant
Let me also check if there's an issue with my fix in the prod path with middleware. Let me look at the existing middleware test to see what is being tested:
Assistant
Let me check my fix in
_renderPagefor the data path - the middleware check needs to be added there too:Assistant
Let me also update the data path in
_renderPageto respect middleware:Assistant
Now let me verify all tests pass:
Assistant
Let me also make sure all related tests still pass:
Assistant
Let me look at the final diff to make sure everything is in order:
Assistant
Let me run the linter and type check:
Assistant
No lint warnings or errors. Let me also run the type check:
Assistant
Excellent! All checks pass. Let me also run the full test suite to make sure I haven't broken anything:
Assistant
All 597 tests pass. Let me also do a final reproduction test to make sure my fix works correctly for the failing tests:
Assistant
All three verification tests pass. Let me clean up:
Assistant
Let me also check the final state of my changes:
Assistant
Let me look at the final diff:
Assistant
Let me also improve the middleware check to be more robust:
Assistant
Let me also improve the dev-server check to be similarly robust:
Assistant
Let me run the final tests:
Assistant
All 289 tests pass. Let me look at the final diff one more time:
Assistant
Let me do one final review of all changes to make sure they are correct:
Assistant
Let me also check that the existing test for
pages-page-response.test.tsstill works:Assistant
Now let me look at the issue checklist and address each point:
Checklist Review
1. If an error was reported in the issue description, I have successfully reproduced it.
Yes, I reproduced the error. Initially confirmed that
GET /ssr(gSSP page) returnedcache-control: nullinstead ofprivate, no-cache, no-store, max-age=0, must-revalidate. The deploy mode data path was also broken because the code accessed which doesn't exist on the runtime object - it should be .Assistant
All my changes are in place. Let me submit:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.