Skip to content

Fix cookie encode option support#93061

Open
afurm wants to merge 1 commit into
vercel:canaryfrom
afurm:af/fix-cookie-encode-option
Open

Fix cookie encode option support#93061
afurm wants to merge 1 commit into
vercel:canaryfrom
afurm:af/fix-cookie-encode-option

Conversation

@afurm

@afurm afurm commented Apr 20, 2026

Copy link
Copy Markdown

What?

Adds support for custom cookie value encoders in Next.js response cookie serialization.

ResponseCookies now honors the encode option when serializing Set-Cookie headers, while preserving encodeURIComponent as the default behavior. The ResponseCookie type also exposes encode so cookies().set() and NextResponse.cookies.set() can accept values like { encode: String }.

Why?

Users integrating with services that expect raw cookie values could not opt out of URL encoding. For example, setting a cookie value like qwerty123= was serialized as qwerty123%3D, even when passing encode: String.

Fixes #64346

How?

  • Patch @edge-runtime/cookies@6.0.0 so stringifyCookie() uses a provided encode function.
  • Regenerate Next.js vendored @edge-runtime/cookies output from the patched dependency.
  • Add regression tests for:
    • NextResponse.cookies.set(..., { encode: String })
    • mutable cookies update callbacks used by cookies().set()

Tests

pnpm testonly packages/next/src/server/web/spec-extension/adapters/request-cookies.test.ts test/unit/web-runtime/next-response-cookies.test.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 39ead5ed4a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/next/src/compiled/@edge-runtime/cookies/index.js
@afurm afurm force-pushed the af/fix-cookie-encode-option branch from 39ead5e to 25315fc Compare April 20, 2026 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Encode isn't an option in Cookie

1 participant