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

This comment has been minimized.

Copy link
Member

@jamuhl 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

This comment has been minimized.

Copy link

@qventura qventura commented Jan 13, 2019

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

This comment has been minimized.

Copy link
Member

@jamuhl 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

This comment has been minimized.

Copy link

@cthurston cthurston commented Jan 30, 2019

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

@jamuhl

This comment has been minimized.

Copy link
Member

@jamuhl jamuhl commented Jan 30, 2019

@cthurston with current published react-i18next@10.0.0-alpha.1? or an old v9

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

@cthurston

This comment has been minimized.

Copy link

@cthurston cthurston commented Jan 30, 2019

I'm using the current published react-i18next@10.0.0-alpha.1. 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

This comment has been minimized.

Copy link
Member

@jamuhl jamuhl commented Jan 30, 2019

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

@cthurston

This comment has been minimized.

Copy link

@cthurston cthurston commented Jan 30, 2019

{
  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

This comment has been minimized.

Copy link
Member

@jamuhl 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

This comment has been minimized.

Copy link
Member

@jamuhl 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

This comment has been minimized.

Copy link

@cthurston cthurston commented Jan 30, 2019

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

This comment has been minimized.

Copy link
Member

@jamuhl 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

This comment has been minimized.

Copy link
Member

@jamuhl jamuhl commented Jan 30, 2019

@cthurston might be fixed in react-i18next@10.0.0-alpha.2

@jamuhl

This comment has been minimized.

Copy link
Member

@jamuhl jamuhl commented Feb 7, 2019

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

@jamuhl jamuhl closed this Feb 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.