js-lingui: Consistent warning that "I18nProvider did not render ..."
When using I18nProvider from @lingui/react in a Next app, I got a consistent console warning every-time warning that
I18nProvider did not render. A call to i18n.activate still needs to happen or forceRenderOnLocaleChange must be set to false.
We load the locale async in an useEffect like
const { locale = 'en' } = useRouter();
useEffect(() => {
async function load(locale: string) {
const { messages } = await import(
`../translations/locales/${locale}/messages.po`
);
i18n.load(locale, messages);
i18n.activate(locale);
}
load(locale);
}, [locale]);
meaning activate will always get called, though not in the initial server side render output. Is this warning an indication of an issue or problem? If so how can I fix it? Setting forceRenderOnLocaleChange to false is not an option as I cannot see a reason why I would not want children to rerender if the user changes the language.
Or is this async locale load simply not the way to do it?
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 12
- Comments: 18 (1 by maintainers)
I ran into the same issue after applying the dynamic loading method. It seems that it is triggered by the
<I18nProvider>component when it is first rendered, before the useEffect hook runs.Maintainers, please correct me if I’m wrong. As far as I can see things still work as expected. The warning doesn’t seem to do any harm, but it is annoying and it is costing developers time because it looks like something that needs to be fixed.
As a workaround, to get rid of the warning, I added two lines to the I18n loader helper, immediately after the call to
i18n.loadLocaleData():This activates the default locale with an empty set of messages, so at least a “dummy locale” is active when
<I18nProvider>is first rendered.@andrii-bodnar I believe this can be closed as the implementation has changed in v4 🙂
Same question as @tommhuth and same setup. Language files are loaded in async/await and only then activate()/load() is called. It seems to be working anyway but quite annoying if it doesn’t really indicate a real issue. It should be possible though according to https://lingui.js.org/guides/dynamic-loading-catalogs.html#final-i18n-loader-helper
I18nProvider did not render. A call to i18n.activate still needs to happen or forceRenderOnLocaleChange must be set to false.Me too.and you need to trans with
Even if you use lingui macro
macro transform you code and set i18 global when local not found
// Provider
model
With redux
effector replace with redux and use createAsyncThunk for handle async import, selectors for data access
@gpessa
@tommhuth You need to set forceRenderOnLocaleChange={false}
And create local instance like this
On ssr I created thunk with webpack dynamic import First SSr render completed with correct locales On static (no ssr) mode app waiting for tryToLoad locale (its quickly operation)