Skip to content

Instantly share code, notes, and snippets.

@nphmuller
Created August 14, 2024 13:55
Show Gist options
  • Save nphmuller/8643b0e162885c985255a9aae6d9420b to your computer and use it in GitHub Desktop.
Save nphmuller/8643b0e162885c985255a9aae6d9420b to your computer and use it in GitHub Desktop.
next set-cookie edge issue
export default function copyHeaders() {
const headers = new Headers();
headers.append("set-cookie", "cookie1=value1");
headers.append("set-cookie", "cookie2=value2");
const response = new Response(undefined, { headers });
console.log(
`before (length ${headers.getSetCookie().length}): `,
headers.getSetCookie()
);
console.log(
`after (length ${response.headers.getSetCookie().length}): `,
response.headers.getSetCookie()
);
}
@nphmuller
Copy link
Author

nphmuller commented Aug 14, 2024

In a page component (or layout etc, Node runtime is important here) there are 2 set-cookie headers in the response.
In a middleware (edge runtime) there will be 2 in "headers" and only 1 in "response".

Evens stranger, the 1 set-cookie header in "response" now contains a single invalid value: 'cookie1=value1, cookie2=value2'.

After upgrading to [email protected] the issue is fixed and there are always 2 set-cookie headers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment