-
Hey everyone, a quick question since I cannot come up with this reading the docs and the examples. Is the locale parameter in page components supposed to be validated by the validation code in the root layout? I've setup a reproduction sandbox here: If you change the URL to an invalid locale you can clearly see the error on the page being thrown on the console although the user is presented with a 404 page. ![]() Is this the expected behaviour from next-intl? I tested this with Next.js 15.1.7 and next-intl 3.26.3. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
That's a great question! The docs currently suggest validation in the root layout, because it works for both static as well as dynamically rendered apps. What Next.js does though, is it renders relevant layouts and pages in parallel, therefore while you're waiting for your root layout to interrupt the render, a page might render as well. If you check out e.g. next-intl/examples/example-app-router/src/app/[locale]/page.tsx Lines 10 to 11 in a881e62 Now, the Behind the scenes, next-intl/examples/example-app-router/src/i18n/request.ts Lines 9 to 11 in a881e62 So what this means is that the call to Now, this is some back and forth that is currently necessary in order to support validation of locales both for static as well as dynamically rendered pages. If you're using static rendering, you should be able to replace the locale validation with The reason why this isn't advocated for in the docs, is because it doesn't work with dynamic pages—therefore for the time being I'm suggesting something that works consistently for either case. That being said, Hope this helps! |
Beta Was this translation helpful? Give feedback.
That's a great question!
The docs currently suggest validation in the root layout, because it works for both static as well as dynamically rendered apps. What Next.js does though, is it renders relevant layouts and pages in parallel, therefore while you're waiting for your root layout to interrupt the render, a page might render as well.
If you check out e.g.
example-app-router
, in a page we're enabling static rendering by callingsetRequestLocale
based on a received locale:next-intl/examples/example-app-router/src/app/[locale]/page.tsx
Lines 10 to 11 in a881e62
Now, the
locale
isn't used directly though, but aut…