Skip to content

Commit b3966d2

Browse files
authored
Fix duplicate cookies (#415)
* fix duplicate cookies in all cases * Create shaggy-chicken-rhyme.md
1 parent e98e014 commit b3966d2

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

.changeset/shaggy-chicken-rhyme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"open-next": patch
3+
---
4+
5+
Fix duplicate cookies

packages/open-next/src/http/openNextResponse.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ export class OpenNextNodeResponse extends Transform implements ServerResponse {
148148
getFixedHeaders(): OutgoingHttpHeaders {
149149
// Do we want to apply this on writeHead?
150150
this.fixHeaders(this.headers);
151+
// This way we ensure that the cookies are correct
152+
this.headers[SET_COOKIE_HEADER] = this._cookies;
151153
return this.headers;
152154
}
153155

@@ -178,16 +180,7 @@ export class OpenNextNodeResponse extends Transform implements ServerResponse {
178180
this.fixHeaders(this.headers);
179181
if (this._cookies.length > 0) {
180182
// For cookies we cannot do the same as for other headers
181-
// We need to merge the cookies, and in this case, cookies generated by the routes or pages
182-
// should be added after the ones generated by the middleware
183-
// This prevents the middleware from overriding the cookies, especially for server actions
184-
// which uses the same pathnames as the pages they're being called on
185-
this.headers[SET_COOKIE_HEADER] = [
186-
...(parseCookies(
187-
this.initialHeaders?.[SET_COOKIE_HEADER] as string | string[],
188-
) ?? []),
189-
...this._cookies,
190-
];
183+
this.headers[SET_COOKIE_HEADER] = this._cookies;
191184
}
192185

193186
if (this.streamCreator) {

0 commit comments

Comments
 (0)