question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Consistent warning that "I18nProvider did not render ..."

See original GitHub issue

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?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:11
  • Comments:17 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
marcvangendcommented, Mar 15, 2022

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():

i18n.load(defaultLocale, {});
i18n.activate(defaultLocale);

This activates the default locale with an empty set of messages, so at least a “dummy locale” is active when <I18nProvider> is first rendered.

2reactions
boy-incertacommented, Feb 18, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

API Reference - React (@lingui/react) - LinguiJS
Default rendering component can be set using defaultComponent prop in <I18nProvider>. The main use case for this is rendering translations in <Text> ...
Read more >
Cannot update a component while rendering a different ...
My error message was: Warning: Cannot update a component ( ForwardRef(BaseNavigationContainer) ) while rendering a different component ...
Read more >
Server Side Rendering – React Aria
Server side rendering, or SSR, is the process of rendering components to HTML on ... SSRProvider will ensure the ids are consistent when...
Read more >
Measuring non-rendered elements in React with Portals
The need of measuring non-rendered elements is not that common. ... In the example above, we defined the rowHeight as a constant as...
Read more >
a context consumer was rendered with multiple children, or a ...
Warning : A context consumer was rendered with multiple children, or a child that isn't a function. A context consumer expects a single...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found