Open semoal opened 3 weeks ago
if you are not using a global t
in your code, i will recommend to create a i18n instance for each render and pass it down the tree. This makes configuration less complicated and avoid all kind of these issues.
We're using the useLingui hook on every component and pass the i18n instance to each t(i18n)
so you can simplify useLinguiInit
to something like that
export function useLinguiInit(messages?: Messages) {
const router = useRouter()
const locale = router.locale || router.defaultLocale!
const i18n = useMemo(
() =>
setupI18n({
locale,
messages: {
[locale]: messages,
},
}),
[messages, locale]
)
return { i18n }
}
Just to note I had a similar issue: https://github.com/lingui/js-lingui/discussions/1816
@semoal is your Next.js project setup with output: "standalone"
?
Just to note I had a similar issue: https://github.com/lingui/js-lingui/discussions/1816
@semoal is your Next.js project setup with
output: "standalone"
?
Yea it is, and Iām still seeing this error sometimes in the production build, usually is shown after the user has expired session and we redirect to login page via getServerSideProps.
Even passing i18n to all t() and initializing as @thekip said
So you need to debug it's on your own. Most likely nextjs skipping calling your root component during some client-side navigation.
PS the concept of hybrid router presented in nextjs is very complex, despite it hiding complexity from end user the complexity is still there. There are many things which can go wrong because some believes it should work like that but in fact it works differently. That creates very hard to catch bugs with weird STRs. That's the price you have to pay working with nextjs (or not pay by choosing many other good frameworks out here)
Describe the bug We're seeing an strange behaviour on Next.js, after a redirect or reload sometimes the translations are lost and we only can see the ids on the screen.
To Reproduce I'm not sure how even is this reproducible, I'll try to reproduce it but couldn't find a way to do it.
Expected behavior To not lose translations.
Additional context Add any other context about the problem here.![image (10)](https://github.com/lingui/js-lingui/assets/22656541/86dd5868-02b2-4e00-8859-07ef6a8d6743)
Code i18n.ts:
_app.ts:
4.7.1
npm list @babel/core
@lingui/swc-plugin
babel-macro-plugin
.babelrc
) or framework you use (Create React App, NextJs, Vite)