Next.js Explained: How cookies() uses AsyncLocalStorage
Ғылым және технология
Learn how the Node.js AsyncLocalStorage API plays a key part in the design of the cookies() function for the Next.js App Router.
◆ Learn Next.js: nextjs.org/learn
◆ Deploy your first project: vercel.com/templates/next.js/...
#vercel
Пікірлер: 24
Would love more videos like this, explaining how Next works under the hood!
I like the intent with this type of video, but there’s quite a bit of assumed knowledge here that makes it hard to follow - especially if you’re not already deep in the App Router/RSC world. Things that were stumbling blocks for me: What is Bun and why are you using it? We’re reading cookies on the server, not the client (I know you mentioned Node.js, but this bears saying explicitly). There’s a circular dependency between the two modules, index and user, in this example; is this just to keep the demo simple, or would you structure these modules this way in the real world? Why is rendering an async operation?
That's cool! I like this format, thank you for making these videos
@leerob
2 ай бұрын
Glad you found it helpful!
Nice video AsyncLocalStorage is awesome 😃👌 Can't wait for it to be standardised in runtimes. AsyncContext is stage 2, wonder if it will move up soon.
nice, please create more in-depth videos like this
great series!
pretty neat stuff
can we apply the same idea for params and searchParams instead of sending it as props to the page component in nextjs ?
Awesome, so this would theoretically work with the pages router too in a next 12 app that doesn't have access to cookies yet?
How do you properly handle localstorage in a next js app
what vs code theme are you using
Can AsyncLocalStorage be used across Middleware and Server Components?
Can we use that API ourselves as well? To store contexty things like current language?
@user-tb4ig7qh9b
2 ай бұрын
Yes it is already used in react native project as a cache
@user-tb4ig7qh9b
2 ай бұрын
It is like built-in redis
I still don’t get it the point of this clip. No idea about Bun, but I can response with cookie something like res.cookie(‘Name’, ‘John’) in express. So what’s the point of using nextjs?
Use cookies() === bye bye SSG?
Wouldn't that be weird if you run Nextjs on a lambda? For example if the user logged in and didn't use the app for some time and the lambda was shut down, well he simply lost his session I suppose if you used cookies to store session like this
@discoverlance
2 ай бұрын
I suppose when a new request comes in, the cookie store will be recreated since it's more of sharing data during the request. And it will always get the cookies from the client or browser request header as seen in parseCookies function so during any request, it will be fresh data from the request.
More under the hood videos please
Let's eat that cookie 😂!
please remove nextjs repo. what a terrible framework but i have to learn it to eat bread.
@twitchizle
2 ай бұрын
Nextjs died with 13