You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
I'm working on an internal project where the edge middleware will dynamically retrieve the defaultLocale and locales and pass the values to createNextIntlMiddleware(). There isn't a way for us to retrieve these values in both server and client components via hooks or async functions. It'd be great if we could get the values without writing our own providers to forward the values from server side to client side.
Describe the solution you'd like
I'd like to propose new hooks and async functions to retrieve current values of defaultLocale and locales which could be set dynamically in the edge middleware just like other existing hooks and async functions:
async getDefautlLocale()
useDefaultLocale()
async getLocales()
useLocales()
I think being explicit is preferrable instead of exposing 1 hook that returns multiple values but I'm opposing such approach.
Describe alternatives you've considered
Writing our own provider to pass the values from the edge middlewares via request.headers to the client components.
Thanks for the question! As you've probably noticed, passing data from the middleware to the RSC render is unfortunately a bit cumbersome currently. next-intl currently limits this to the locale that is received by the [locale] segment in your app, but further additions are not planned currently.
I think your options currently are:
The workaround with the header that you've shared
Running the logic for fetching your default locale and locales in a Server Component again
That being said, it seems like the Next.js team is working on revamping the middleware: vercel/next.js#46722 (comment). I found this particular sentence in the announcement interesting:
Then, you could pass data to the rendering phase.
As far as I'm aware, there's no clarification available currently on what this means, but maybe it could work for your use case in the future!
I'll close this as this particular feature is currently not planned.
Is your feature request related to a problem? Please describe.
I'm working on an internal project where the edge middleware will dynamically retrieve the
defaultLocale
andlocales
and pass the values tocreateNextIntlMiddleware()
. There isn't a way for us to retrieve these values in both server and client components via hooks or async functions. It'd be great if we could get the values without writing our own providers to forward the values from server side to client side.Describe the solution you'd like
I'd like to propose new hooks and async functions to retrieve current values of
defaultLocale
andlocales
which could be set dynamically in the edge middleware just like other existing hooks and async functions:async getDefautlLocale()
useDefaultLocale()
async getLocales()
useLocales()
I think being explicit is preferrable instead of exposing 1 hook that returns multiple values but I'm opposing such approach.
Describe alternatives you've considered
Writing our own provider to pass the values from the edge middlewares via
request.headers
to the client components.The text was updated successfully, but these errors were encountered: