Skip to content

fix: checks when Next.js' implementation of ResponseCookies._headers is undefined now #2119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/runtime/src/templates/edge-shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export const addMiddlewareHeaders = async (
}

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

Expand Down Expand Up @@ -191,7 +193,8 @@ export const buildResponse = async ({
}

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

Expand Down