-
Notifications
You must be signed in to change notification settings - Fork 49
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
feat: add Next.js 15+ support #86
Conversation
feat: add Next.js 15+ support
@andreizanik I'd love to hear from you if it makes sense :) Thanks! |
Hello @joaopcm! Great job! Thanks to you, we’re almost ready to support Next.js v15 just one day after its release. I noticed one key point in your PR that I believe needs adjustment. From what I understand, your changes make every function asynchronous, which is fine overall. However, for client components, we should keep the synchronous versions. Otherwise, users will need to add extra code in client components to handle this behavior. I suggest that we return promises only for the server-side code. I realize this will require some extra |
Hey @greg2012201! It makes sense! I'll work on it and update the PR. Can I mention you once I get it done so we can review it again? |
Sure! I'm looking foward to your updates. |
…pdate package.json, split tests
Does this change the peerDependency of this package from Next 14 to Next 15 or will it support both? Mind adding that entry into Great work chaps! Thank you. |
- replaced and with and for better clarity and alignment with Next.js conventions - simplified cookie transformation and validation functions to use - removed redundant type definitions and moved relevant types to a centralized file - improved error handling by formatting error messages for better readability - deleted unused file to reduce code duplication and maintain consistency across the codebase
Hey @will-stone @greg2012201 @andreizanik, I thought a lot about how to keep the DX for client-side environments synchronous and maintain asynchronicity only for server-side environments. I made a small adjustment to the library's structure. The current (or old) way of using it remains valid. You can import functions directly from If the import is done directly from If someone tries to import That said, here are some other changes I made:
Given all this context, the PR is ready to be reviewed again @greg2012201 @andreizanik. I also want to clarify it that it is not enough for the tests with Jest to pass for both client and server side, but I also ensured to test the full functionality of version 5.0.0 in an existing project with Next.js 15.0.0 on both server and client side. Server-side tests passingClient-side tests passingHit me up if you need anything from me! Happy to help! Thank you! |
Hey @joaopcm I need to look at everything in more detail, but I'll take a while because because I'm mad busy with work |
Nice approach @joaopcm! I appreciate the code structure reorganization and have delved into your changes. I tested them on both the client and server components. However, there's an issue in the client component during its server phase, as it relies on window. When the client component is pre-rendered on the server, getCookie runs, but an exception is thrown: I believe we should avoid relying on PS: I haven't tested it in middleware, server actions, route handlers |
Hi @joaopcm, your check ensureClientSide unfortunately doesn't cover case when you use cookie inside client component without wrap in hooks, so in render time window is undefined and I get error. |
So just changing |
Guys, I'll be a bit busy in the upcoming days and might not have enough time to keep this PR moving forward until the end of next week. If you want to take this PR over, feel free to do it! Otherwise, I'll get back and update it in a few days. Sorry for that! |
@joaopcm @andreizanik This is the continuation: #87 |
Hey, we tried to upgrade the package but now we're getting Type errors since the serve cookie functions return promises. Is there any way to use the updated lib without the use of promises for server? |
If you try to use
cookies-next
with the brand-new Next.js version 15.0.0, your app will break due to the new async usage ofcookies()
fromnext/headers
.This PR introduces a new breaking change for
cookies-next
, version 5.0.0, which adds support for the new Next.js version as well, so we can continue using it in our projects while we upgrade them to the latest Next.js version.Additionally, I took the opportunity to add a certain level of tests to ensure it works as expected and updated its documentation to clarify and reflect the new changes from the Next.js team.
I have a big project running on top of Next.js 14. Yesterday, I tried to upgrade it to Next.js 15, but it started to fail due to the incompatibility between the new Next.js
next/headers
API andcookies-next
, so I decided to bring up this PR.After finishing the changes for this library, I tested it in that project already migrated to the latest Next.js version and it just works.
I hope you find this helpful! Happy to help! Cheers!