-
Notifications
You must be signed in to change notification settings - Fork 280
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
fix(nextjs): Skip NextResponse normalization in mergeResponses if possible #2244
fix(nextjs): Skip NextResponse normalization in mergeResponses if possible #2244
Conversation
🦋 Changeset detectedLatest commit: 18ae827 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
.addFile( | ||
'src/app/provider.tsx', | ||
() => `'use client' | ||
import { ClerkProvider } from "@clerk/nextjs" | ||
|
||
export function Provider({ children }: { children: any }) { | ||
return ( | ||
<ClerkProvider> | ||
{children} | ||
</ClerkProvider> | ||
) | ||
}`, | ||
) | ||
.addFile( | ||
'src/app/layout.tsx', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test did not run without these additions. The next-build.test.ts
file has the same additions.
Why is the base template not just including these?
response2.cookies.set('foo', '1'); | ||
response2.cookies.set({ | ||
name: 'second', | ||
value: '2', | ||
path: '/', | ||
sameSite: 'none', | ||
secure: true, | ||
}); | ||
response2.cookies.set('bar', '1', { | ||
sameSite: 'none', | ||
secure: true, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The user reproduction used this format and while adding it the tests failed because sameSite
and secure
weren't passed through
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LekoArts I can't speak much to your question around the integration tests, but having paired with you on the initial issue, this all looks good to me!
Just one small suggestion around removing the console.log
. 👍
Co-authored-by: Tom Milewski <[email protected]>
…sible (#2244) * fix(nextjs): If res is NextResponse just return it * fix(nextjs): Support options when setting cookies * chore(repo): Add initial next middleware test * chore(repo): Make test work * chore(repo): Add changeset * Update packages/nextjs/src/utils/response.test.ts Co-authored-by: Tom Milewski <[email protected]> --------- Co-authored-by: Tom Milewski <[email protected]> (cherry picked from commit b892ac6)
…sible (#2244) (#2260) * fix(nextjs): If res is NextResponse just return it * fix(nextjs): Support options when setting cookies * chore(repo): Add initial next middleware test * chore(repo): Make test work * chore(repo): Add changeset * Update packages/nextjs/src/utils/response.test.ts Co-authored-by: Tom Milewski <[email protected]> --------- Co-authored-by: Tom Milewski <[email protected]> (cherry picked from commit b892ac6) Co-authored-by: Lennart <[email protected]>
…sible (#2244) * fix(nextjs): If res is NextResponse just return it * fix(nextjs): Support options when setting cookies * chore(repo): Add initial next middleware test * chore(repo): Make test work * chore(repo): Add changeset * Update packages/nextjs/src/utils/response.test.ts Co-authored-by: Tom Milewski <[email protected]> --------- Co-authored-by: Tom Milewski <[email protected]>
Description
In the
mergeResponses
helper insidenextjs
we normalize the incoming responses (which can beNextResponse
orResponse
) by passing through theres
to anew NextResponse()
.In that process somehow the
cookies
are getting removed (except for the first one). This PR addresses this issue by just skipping this normalization if the incoming reponse is already aNextResponse
.Additionally, while updating some unit tests I also saw that we didn't pass along the
options
forcookies.set()
.Fixes #1897
Checklist
npm test
runs as expected.npm run build
runs as expected.Type of change
Packages affected
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/clerk-expo
@clerk/fastify
gatsby-plugin-clerk
@clerk/localizations
@clerk/nextjs
@clerk/clerk-react
@clerk/remix
@clerk/clerk-sdk-node
@clerk/shared
@clerk/themes
@clerk/types
build/tooling/chore