js-lingui
js-lingui copied to clipboard
Ids are displayed sometimes on production build
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.
Code i18n.ts:
export function useLinguiInit(messages?: Messages) {
const router = useRouter();
const locale = router.locale || router.defaultLocale!;
const isClient = typeof window !== "undefined";
if (!isClient && locale !== i18n.locale) {
// there is single instance of i18n on the server
// note: on the server, we could have an instance of i18n per supported locale
// to avoid calling loadAndActivate for (worst case) each request, but right now that's what we do
i18n.loadAndActivate({ locale, messages });
}
if (isClient && (i18n.locale === "" || i18n.locale === undefined)) {
// first client render
i18n.loadAndActivate({ locale, messages });
activateDayjsLocale(locale);
}
useEffect(() => {
const localeDidChange = locale !== i18n.locale;
if (localeDidChange) {
i18n.loadAndActivate({ locale, messages });
activateDayjsLocale(locale);
}
}, [locale, messages]);
return { i18n };
}
_app.ts:
const { i18n } = useLinguiInit(pageProps.translation);
<I18nProvider i18n={i18n}>
....
- jsLingui version
4.7.1 - Babel version
npm list @babel/core - Macro support:
- [X] I'm using SWC with
@lingui/swc-plugin - [ ] I'm using Babel with
babel-macro-plugin - [ ] I'm not using macro
- Your Babel config (e.g.
.babelrc) or framework you use (Create React App, NextJs, Vite)