mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #1072] [MERGED] refactor(shims): dedupe cookie value serialization #1069
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#1069
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/cloudflare/vinext/pull/1072
Author: @james-elicx
Created: 5/5/2026
Status: ✅ Merged
Merged: 5/5/2026
Merged by: @james-elicx
Base:
main← Head:refactor/dedupe-cookie-serialization📝 Commits (2)
8960d16refactor(shims): dedupe cookie value serialization2fd7dfefix(shims): drop unused export of SerializeSetCookieOptions📊 Changes
3 files changed (+92 additions, -83 deletions)
View changed files
📝
packages/vinext/src/shims/headers.ts(+6 -46)➕
packages/vinext/src/shims/internal/cookie-serialize.ts(+83 -0)📝
packages/vinext/src/shims/server.ts(+3 -37)📄 Description
Summary
Extract the shared Set-Cookie serialization from the next/headers and next/server shims into a single helper at
packages/vinext/src/shims/internal/cookie-serialize.ts. Follow-up to #1049.The two call sites —
cookies().set()inheaders.tsandResponseCookies.set()inserver.ts— were producing byte-for-byte identical Set-Cookie strings via copy-pasted code (sameencodeURIComponent(value), same defaultPath=/, same attribute order: Path → Domain → Max-Age → Expires → HttpOnly → Secure → SameSite, same validators). Pure refactor — no behavior change.The third candidate site,
RequestCookies._serializeinserver.ts:574, builds a requestCookie:header (name=value; name=value, no attributes) — different format, intentionally left alone.What moved
packages/vinext/src/shims/internal/cookie-serialize.ts(new):serializeSetCookie(name, value, options)— builds the full Set-Cookie value stringvalidateCookieName(name)— RFC 6265 §4.1.1 token validatorvalidateCookieAttributeValue(value, attr)— control-char/semicolon guardThe validators were also duplicated verbatim across both files; consolidating them avoids subtle drift.
Why a separate module instead of importing across shims
server.tsdeliberately avoids static-importingheaders.tsbecause of a Vite "use cache" transform issue (existing comment inserver.ts:18-30). The new helper lives underinternal/alongsideparse-cookie-header.ts, mirroring the existing pattern.Files changed
packages/vinext/src/shims/internal/cookie-serialize.ts(new, 84 lines)packages/vinext/src/shims/headers.ts(-43 lines, unchanged behavior)packages/vinext/src/shims/server.ts(-37 lines, unchanged behavior)Net: 9 insertions, 79 deletions across the two existing files.
Test plan
pnpm vp test run tests/app-router.test.ts— 308 tests passpnpm vp test run tests/pages-router.test.ts— 200 tests pass (one pre-existingafterAlltimeout in the unrelatedallowedDevOriginssuite, reproduces onmainwithout these changes)pnpm vp test run tests/shims.test.ts tests/app-route-handler-execution.test.ts tests/app-page-execution.test.ts tests/api-handler.test.ts— 912 tests passpnpm tsc --noEmit(inpackages/vinext) — cleanpnpm fmt --writeon touched files🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.