-
-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No SSR lang in useTranslation #291
Comments
@darren-charterindex thanks to report it! |
@darren-charterindex can you provide the generated page code? |
I tried with |
I'm using a function component with no getStaticProps, getServerSideProps, or HOC. Just using the |
The generated code:
|
I am using the build step, and not the |
Contrary to my first report, actually on SSR, it logs three times when First time:
Second time (there is no next-translate errors this time):
Third time (with populated lang):
|
The only HOC wrapping the |
Sorry @darren-charterindex , but I can't reproduce it, all the time logs only 1 |
No problem @aralroca, thank you for taking a look, and thank you for next-translate 👍 I suspect it's a race condition, with Apollo hydrating the state. I've reverted to 0.18.0 for now as this is working fine. |
@darren-charterindex Have you tried to use the import { userRouter } from 'next/router'
// ...
const { locale } = useRouter()
console.log({ lang: locale }) |
This solves the issue of requiring the locale for other purposes, such as for querying a localised api. However
|
I've also noticed upon moving to 0.19.0 that the build changed it's interpretation of some pages. Where previously built as |
0.19.1-canary.1 fixes the issue. Thank you 👍 |
I was just going to ask you. Very happy to hear it! Thank you for reporting the issue! 😊 Besides the warning log, the
Yes, in this release we have changed the way the pages are assembled. Now in fact the structure is exactly the same as you have in It may seem like a backward step... Pages, before, were duplicated for each language, becoming totally static without needing SSG. However, this blocked further evolution of the library by adapting the i18n changes that Next.js is developing. I think it is a small cost to pay, since from static to SSG there is not much difference either, only that it is generated at the moment Next.js does its internal build. Thanks to this, in version 1.0.0 of next-translate we probably don't need the "build step" anymore, since now the next step that Next.js team is developing is to provide a way to load the translations, which is exactly why in version 0.19 we still need the "build step". All these steps are being taken by listening to people how they use i18n in their projects, naturally, if you see that we are taking a wrong step, you can contribute your ideas on how to evolve the library in this issue. |
After migration to 0.19, and making the required changes, lang is undefined during the SSR. It is the expected string again during the CSR.
The text was updated successfully, but these errors were encountered: