Skip to content

Commit f051e22

Browse files
authored
fix: checks when Next.js' implementation of ResponseCookies._headers is undefined now (#2119)
* fix: checks when Next.js' implementation of ResponseCookies._headers is undefined now * chore: trigger build
1 parent 49ada27 commit f051e22

File tree

1 file changed

+4
-1
lines changed
  • packages/runtime/src/templates/edge-shared

1 file changed

+4
-1
lines changed

packages/runtime/src/templates/edge-shared/utils.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ export const addMiddlewareHeaders = async (
5858
}
5959

6060
interface ResponseCookies {
61+
// This is non-standard that Next.js adds.
62+
// See github.com/vercel/next.js/blob/de08f8b3d31ef45131dad97a7d0e95fa01001167/packages/next/src/compiled/@edge-runtime/cookies/index.js#L158
6163
readonly _headers: Headers
6264
}
6365

@@ -191,7 +193,8 @@ export const buildResponse = async ({
191193
}
192194

193195
// NextResponse doesn't set cookies onto the originResponse, so we need to copy them over
194-
if (response.cookies._headers.has('set-cookie')) {
196+
// In some cases, it's possible there are no headers set. See https://github.com/netlify/pod-ecosystem-frameworks/issues/475
197+
if (response.cookies._headers?.has('set-cookie')) {
195198
response.originResponse.headers.set('set-cookie', response.cookies._headers.get('set-cookie')!)
196199
}
197200

0 commit comments

Comments
 (0)