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.

Suspense not triggered on language change

See original GitHub issue

Describe the bug I’m using almost exact code as in the example and Suspense is triggered only on the initial render (showing loading component). However it is not triggered when i18n.changeLanguage() is called inside onClick event handler. I’m using XHR backend for locale load and after button is clicked request is being sent to the server but nothing happens until everything is fetched.

I tried to set useSuspense to false but in such case ready flag never gets back to undefined of false (on component re-render) and just re-renders component with true value after async language change finishes.

Occurs in react-i18next version 10.6.0

Expected behaviour When this code is executed Suspense should trigger and display fallback component before all messages are fetched and language is fully changed.

const handleClick = lng => {
    i18n.changeLanguage(lng);
  //^^^^^^^^^^^^^^^^^^^^^^^^
  //This returns unhandled Promise
};

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
jamuhlcommented, Apr 25, 2019

ok gone the additional event way…

can you try with:

  • i18next@15.1.0
  • react-i18next@10.9.0
0reactions
jamuhlcommented, Apr 25, 2019

If you encounter any issues with it - let me know.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is react i18next not working ? no errors
So I think when you are saying in loadPath that load files from ./translations/{{lng}}/common. json , the request actually gets resolved to ...
Read more >
useTranslation (hook)
The useTranslation hook will trigger a Suspense if not ready (eg. pending load of translation files). You can set useSuspense to false if...
Read more >
How to properly internationalize a React application using ...
We are going to adapt the app to detect the language according to the user's preference. And we will create a language switcher...
Read more >
React i18n: A step-by-step guide to React-intl - Lokalise Blog
With localization, you can customize not only the language ... also accommodates experimental support for the API on React suspense.
Read more >
React lazy, Suspense and Concurrent React Breakdown with ...
Implementing Suspense is also straight forward, and does not require a big change to your JSX markup. Import Suspense from the standard React...
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