AsyncLocalStorage From middleware to server component #76582
Replies: 4 comments 10 replies
-
This is blocking opral/inlang-paraglide-js#245. A related issue seems to be #53466. |
Beta Was this translation helpful? Give feedback.
-
@KevinEonix I think this is confusing how Middleware operates in Next.js—it's not meant to pass information down to Server Components. Middleware and your Next.js application are not running in the same context (not running on the same thread). @samuelstroschein I don't think this is related to opral/inlang-paraglide-js#245, but maybe you have more context as to why
You actually can, you just have to use it in the right context. For example with Route Handlers, https://nextjs.org/docs/app/building-your-application/deploying#after. |
Beta Was this translation helpful? Give feedback.
-
@samcx please just make middleware's and async local storage work as it does in every other framework. fact is: there is no way to pass information from a middleware to server components in a sync way which will block paraglide js usage in nextjs. fact is also: that every other metaframework middleware just works. this is, as more often than not over the past two years, a nextjs only problem.
This is related because I have to implement the middleware in propriety NextJS API that is about to break because it's becoming async. My problem is solved if AsyncLocalStorage would just work (as it does in any other SSR framework).
I appreciate your response but this is a prime example of what is wrong with nextjs atm. Passing information to the rendering tree from a middleware is required. NextJS has an internal mechanism to leverage AsyncLocalStorage, or an equivalent mechanism, to pass cookies and headers because this is such a basic requirement. Instead of making this API available to developers, you recommend I dig deep into NextJS internals/docs to figure out how I can use Route Handlers. Sorry but no. I am not investing that time to learn NextJS specific APIs that I need to learn because APIs that just work everywhere else don't work in NextJS |
Beta Was this translation helpful? Give feedback.
-
What is the current status of this? Need to use paraglide for i18n. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Link to the code that reproduces this issue
https://github.com/KevinEonix/next-asyncLocalStorage
To Reproduce
Context is undefined :(
Current vs. Expected behavior
The phrase should be
test value in store is test value
Provide environment information
Which area(s) are affected? (Select all that apply)
Developer Experience, Middleware
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
I tested that on an other project and have the same problem (same machine sane versions)
Beta Was this translation helpful? Give feedback.
All reactions