Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Not all namespaces are loaded when passing the lng option to useTranslate #1809

Closed
pvdstel opened this issue Nov 7, 2024 · 3 comments
Closed

Comments

@pvdstel
Copy link

pvdstel commented Nov 7, 2024

🐛 Bug Report

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:
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.

unexpected-race

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 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:
expected-behavior

Simply asking i18next to provide a specific language shouldn't cause namespaces to not load in.

Your Environment

  • runtime version: Node v22.11.0. Browsers: Firefox Developer Edition 133, Chrome 130.0.6723.117.
  • i18next version: 23.16.4.
  • react-i18next version: 15.1.0.
  • os: Windows.
@adrai
Copy link
Member

adrai commented Nov 7, 2024

Can you try with v15.1.1 ?

@pvdstel
Copy link
Author

pvdstel commented Nov 7, 2024

That version works, both in the minimal example and in the larger application. Thank you! 😄

@adrai
Copy link
Member

adrai commented Nov 7, 2024

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.

There are many ways to help this project 🙏

@adrai adrai closed this as completed Nov 7, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants