Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Infiinite loop caused #673

Closed
developdeez opened this issue Jan 13, 2019 · 14 comments
Closed

Infiinite loop caused #673

developdeez opened this issue Jan 13, 2019 · 14 comments

Comments

@developdeez
Copy link

developdeez commented Jan 13, 2019

I keep getting infinite loop errors when using the HOC 'withNamespaces'
I put it on a child component of a page that is also translated.

@jamuhl
Copy link
Member

jamuhl commented Jan 13, 2019

please provide a https://codesandbox.io/s/l4qrory2nl to reproduce 99.9% sure not related to this module but to either your code or misconfiguration

@qventura
Copy link

If it can help, I had a similar issue when I set a fallbackLng that has no corresponding resources

@jamuhl jamuhl added the v9 label Jan 30, 2019
@jamuhl
Copy link
Member

jamuhl commented Jan 30, 2019

please start adding changes related to the v9 version to the v9.x.x branch (master will be now for the upcoming v10 hooks)

--> https://github.com/i18next/react-i18next/tree/v9.x.x

@cthurston
Copy link

I'm getting an infinite loop when the backend fails to load. Probably related, but I'm using alpha v10.

@jamuhl
Copy link
Member

jamuhl commented Jan 30, 2019

@cthurston with current published [email protected]? or an old v9

think i fixed that...376fe57#diff-cfd6b2fa22409acc10b6dab14d52cdb1R51

@cthurston
Copy link

cthurston commented Jan 30, 2019

I'm using the current published [email protected]. For some reason it is sending an empty languages array. This causes ready to always be false. Near line 45 in useTranslation. If I put a guard in the every callback, it seems not to crash.

var ready = i18n.isInitialized && namespaces.every(function (n) {
    if(!i18n.languages || !i18n.languages.length) return true

Until I added the languagedetector back in. Then it hit an infinite loop again.

For now I'm just returning true from the callback, seems to work.

@jamuhl
Copy link
Member

jamuhl commented Jan 30, 2019

can you paste your i18next options? wondering how i18n.languages can be empty after init

@cthurston
Copy link

{
  fallbackLng: 'en',
  ns: ['default'],
  defaultNS: 'default',
  fallbackNS: 'default',
  nsSeparator: '::',
  keySeparator: '::',
  debug: true,
  interpolation: {
    escapeValue: false, // not needed for react!!
  },
  backend: {
    loadPath: `${REACT_APP_API_SERVER}/locales/{{lng}}/{{ns}}/translation.json`,
    crossDomain: true,
  },
}

@jamuhl
Copy link
Member

jamuhl commented Jan 30, 2019

strange if isInitialized is set on i18next languages should be at least ['en'] - really don't get how i18next.languages can be undefined

@jamuhl
Copy link
Member

jamuhl commented Jan 30, 2019

  const ready =
    i18n.isInitialized &&
    namespaces.every(n => {
      const ret =
        i18n.hasResourceBundle(i18n.languages[0], n) ||

So guess it's an empty array...i'm confused

@cthurston
Copy link

var ready = i18n.isInitialized && namespaces.every(function (n) {
    console.log('Ready?', n, i18n.languages)

Without language detector:
screen shot 2019-01-30 at 12 06 33 pm

But even with language detector and languages ['en', 'en-US'] it still hits an infinite loop if the backend doesn't respond.

@jamuhl
Copy link
Member

jamuhl commented Jan 30, 2019

ah...if not using a detector you need to set lng: 'en|de|fr' lng to whatever you want it to be.

Wonder if we should force taking the fallbackLng as lng if not set by user -> seems not to be clear it has to be set when not using a detector?!?

ok if backend fails completely it will never get ready - will make a check for everything failing to load

@jamuhl
Copy link
Member

jamuhl commented Jan 30, 2019

@cthurston might be fixed in [email protected]

@jamuhl
Copy link
Member

jamuhl commented Feb 7, 2019

closing for now...feel free to provide a sample to reproduce.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants