[PR #281] [MERGED] fix: apply headers, cookies, and status set by getServerSideProps to the response #440

Closed
opened 2026-05-06 12:39:49 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/281
Author: @southpolesteve
Created: 3/6/2026
Status: Merged
Merged: 3/6/2026
Merged by: @southpolesteve

Base: mainHead: fix/render-page-response-headers


📝 Commits (2)

  • 85273a0 fix: apply headers, cookies, and status set by getServerSideProps to the response
  • 599b5ef refactor: explicitly forward gSSP headers in dev server

📊 Changes

5 files changed (+155 additions, -11 deletions)

View changed files

📝 packages/vinext/src/index.ts (+37 -6)
📝 packages/vinext/src/server/dev-server.ts (+54 -5)
tests/fixtures/pages-basic/pages/ssr-headers.tsx (+26 -0)
tests/fixtures/pages-basic/pages/ssr-res-end.tsx (+16 -0)
📝 tests/pages-router.test.ts (+22 -0)

📄 Description

Summary

  • getServerSideProps receives a res object that supports setHeader(), statusCode, and end(). Previously, headers/cookies/status set on this object were silently discarded in the final HTML response.
  • Fixed the production path (renderPage in index.ts): the mock res object's accumulated state is now merged into the final Response, including custom headers, Set-Cookie values, and non-200 status codes
  • Fixed the dev server path (dev-server.ts): res.statusCode set by gSSP is now preserved through streamPageToResponse, and res.end() short-circuit is detected to avoid writing to an already-ended stream
  • Added getHeaders() and headersSent to the mock res object in createReqRes so callers can read accumulated response metadata
  • Added fixture pages and integration tests covering: custom headers, cookies, status codes, and res.end() short-circuit behavior

Test plan

Two new fixture pages:

  • pages/ssr-headers.tsx — gSSP sets x-custom-header, a Set-Cookie, and statusCode = 201
  • pages/ssr-res-end.tsx — gSSP calls res.end() with a JSON body and status 202

Two new integration tests in pages-router.test.ts verify headers, cookies, status, and short-circuit behavior.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/281 **Author:** [@southpolesteve](https://github.com/southpolesteve) **Created:** 3/6/2026 **Status:** ✅ Merged **Merged:** 3/6/2026 **Merged by:** [@southpolesteve](https://github.com/southpolesteve) **Base:** `main` ← **Head:** `fix/render-page-response-headers` --- ### 📝 Commits (2) - [`85273a0`](https://github.com/cloudflare/vinext/commit/85273a05e2e46d46cc9577166ce9a15aca1961bb) fix: apply headers, cookies, and status set by getServerSideProps to the response - [`599b5ef`](https://github.com/cloudflare/vinext/commit/599b5efbfb1b9e896c7783f5d1dab223e36781e9) refactor: explicitly forward gSSP headers in dev server ### 📊 Changes **5 files changed** (+155 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/index.ts` (+37 -6) 📝 `packages/vinext/src/server/dev-server.ts` (+54 -5) ➕ `tests/fixtures/pages-basic/pages/ssr-headers.tsx` (+26 -0) ➕ `tests/fixtures/pages-basic/pages/ssr-res-end.tsx` (+16 -0) 📝 `tests/pages-router.test.ts` (+22 -0) </details> ### 📄 Description ## Summary - `getServerSideProps` receives a `res` object that supports `setHeader()`, `statusCode`, and `end()`. Previously, headers/cookies/status set on this object were silently discarded in the final HTML response. - Fixed the production path (`renderPage` in `index.ts`): the mock `res` object's accumulated state is now merged into the final `Response`, including custom headers, Set-Cookie values, and non-200 status codes - Fixed the dev server path (`dev-server.ts`): `res.statusCode` set by gSSP is now preserved through `streamPageToResponse`, and `res.end()` short-circuit is detected to avoid writing to an already-ended stream - Added `getHeaders()` and `headersSent` to the mock `res` object in `createReqRes` so callers can read accumulated response metadata - Added fixture pages and integration tests covering: custom headers, cookies, status codes, and `res.end()` short-circuit behavior ## Test plan Two new fixture pages: - `pages/ssr-headers.tsx` — gSSP sets `x-custom-header`, a `Set-Cookie`, and `statusCode = 201` - `pages/ssr-res-end.tsx` — gSSP calls `res.end()` with a JSON body and status 202 Two new integration tests in `pages-router.test.ts` verify headers, cookies, status, and short-circuit behavior. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 12:39:49 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#440
No description provided.