You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When passing the same value in the lng prop to the options of useTranslation with different namespaces, only one namespace is loaded. This causes the Suspense fallback to be shown forever, as i18next never attempts to load other namespaces. The behavior is related to this section of code, where it notices that lng is set, and only attempts to load the language. While debugging, I found that i18next notices that it does not need to load new languages, so it bails out early, even if more namespaces should be loaded.
Note that the translations are loaded lazily.
Unexpected behavior:
I would like to note that the problem still occurs when useSuspense is disabled, but then it appears to be a race condition as to which files are loaded and which are not. It does not trigger Suspense, but the translations simply are not ready.
The file src/fixedLanguage.ts contains a value which can be toggled for demonstrating the unexpected behavior. This value controls whether the value passed to the lng option is 'en' or undefined. When undefined is passed, the behavior is as if lng is not set, giving the expected results. But if we set lng to 'en', only the first translation is ever loaded in.
To run:
pnpm install
pnpm dev
Then follow the instructions in the terminal as Vite has launched a development server.
Expected behavior
I expect all required namespaces to be loaded in, and for the Suspense to disappear eventually:
Simply asking i18next to provide a specific language shouldn't cause namespaces to not load in.
If you like this module don’t forget to star this repo. Make a tweet, share the word or have a look at our https://locize.com to support the devs of this project.
🐛 Bug Report
When passing the same value in the
lng
prop to the options ofuseTranslation
with different namespaces, only one namespace is loaded. This causes theSuspense
fallback to be shown forever, as i18next never attempts to load other namespaces. The behavior is related to this section of code, where it notices thatlng
is set, and only attempts to load the language. While debugging, I found that i18next notices that it does not need to load new languages, so it bails out early, even if more namespaces should be loaded.Note that the translations are loaded lazily.
Unexpected behavior:
I would like to note that the problem still occurs when
useSuspense
is disabled, but then it appears to be a race condition as to which files are loaded and which are not. It does not trigger Suspense, but the translations simply are not ready.To Reproduce
Repository: https://github.com/pvdstel/react-i18next-forced-language-unexpected-suspense
The file
src/fixedLanguage.ts
contains a value which can be toggled for demonstrating the unexpected behavior. This value controls whether the value passed to thelng
option is'en'
orundefined
. Whenundefined
is passed, the behavior is as iflng
is not set, giving the expected results. But if we setlng
to'en'
, only the first translation is ever loaded in.To run:
Then follow the instructions in the terminal as Vite has launched a development server.
Expected behavior
I expect all required namespaces to be loaded in, and for the Suspense to disappear eventually:
Simply asking i18next to provide a specific language shouldn't cause namespaces to not load in.
Your Environment
The text was updated successfully, but these errors were encountered: