3 ms·
Agree, this is a strange framework decision and I also hit this recently. I think the TLDR is that you can't mutate cookies in server components so that they c
by rgbrgb 2y ago
Agree, this is a strange framework decision and I also hit this recently.
I think the TLDR is that you can't mutate cookies in server components so that they can fully support HTML streaming. The workaround is doing a second request from the client to update the cookie. Kind of fuel for the conspiracy theories around app router being about driving vercel revenue.
FWIW I'd gladly opt-out of streaming to eliminate the cost and complexity of making a second request.
- leerob 2y agoSince HTTP does not allow setting cookies after streaming starts, you can't set cookies from a page or layout directly. Next.js believes response streaming is a tradeoff worth making, so if you don't want or need streaming, then Next.js might not be the right choice for your app. If you're wondering "why streaming?": https://vercel.com/blog/how-streaming-helps-build-faster-web-applications https://vercel.com/blog/how-streaming-helps-build-faster-web...
- rgbrgb 2y agothanks for the link! i hear you on not having to build for everyone and it's good to take a stance and not be for everyone / every use case. dhh talked about this at railsworld recently [0]. i think i've got it working ok with the second request to update the session (as suggested here [1]). [0]: https://www.youtube.com/watch?v=zPBbHu-BKpQ https://www.youtube.com/watch?v=zPBbHu-BKpQ [1]: https://github.com/nextauthjs/next-auth/discussions/9715 https://github.com/nextauthjs/next-auth/discussions/9715
- hysan 2y ago> if you don't want or need streaming, then Next.js might not be the right choice for your app. I'm glad to see this stated so clearly. It's important for frameworks to be upfront about the use cases being served and the trade-offs that are being made. I think a lot of the negativity that I see on the web is because Next.js was the right choice [for them] in the past, but once it moved towards streaming as the primary paradigm, those same people probably are feeling left in the dust. I think it would be good for the Next.js team to reiterate this and/or make it more clear in the docs so that new devs can make informed decisions when evaluating Next.js for their next project.
- rgbrgb 2y agoagree, this statement should be in the docs. didn’t realize app router wasn’t intended for my use case