jsverse / transloco

🚀 😍 The internationalization (i18n) library for Angular
https://jsverse.github.io/transloco/
MIT License
2.04k stars 197 forks source link

Bug(transloco): recursive http calls if multiple scopes are not found #647

Open dmitry-stepanenko opened 1 year ago

dmitry-stepanenko commented 1 year ago

Is there an existing issue for this?

Which Transloco package(s) are the source of the bug?

Transloco

Is this a regression?

Yes

Current behavior

If multiple language scopes could not be loaded simultaneously, the application starts infinite recursive calls.

To reproduce, make the following change in this file transloco/apps/transloco-playground/src/app/scope-sharing/scope-sharing.module.ts:

providers: [
    {
      provide: TRANSLOCO_SCOPE,
      useValue: [{
        scope: 'todos-page1',
        alias: 'todos1',
      }, {
        scope: 'todos-page2',
        alias: 'todos2',
      }],
    },
...

This sets 2 scopes that cannot be resolved. If you open http://localhost:4200/scope-sharing after this, you will see infinite recursive http calls

image

Expected behavior

Should attempt to load the scope once and exit with a failure.

Please provide a link to a minimal reproduction of the bug, if you won't provide a link the issue won't be handled.

reproduction steps described above

Transloco Config

No response

Please provide the environment you discovered this bug in

Transloco: 4.2.6
Angular: 15.1.0
Node: 16
Package Manager: npm
OS: MacOS

Browser

No response

Additional context

No response

I would like to make a pull request for this bug

No

shaharkazaz commented 1 year ago

Out of curiosity:

  1. Did you reach this bug in a real use-case?
  2. If you need both scopes in the same component, why split them?
dmitry-stepanenko commented 1 year ago

We have a large monorepo with multiple applications, that need certain shared features. Each of those features is large and has a lot of translations in it.

Something like this:

shared/
  feature1/
    translation-scope-1
  feature2/
    translation-scope-2
  feature3/
    translation-scope-3

Each app is able to load only those translations it needs. E.g. app1 needs translation-scope-1 and translation-scope-3, app2 needs only translation-scope-3 and so on. Overall there're like 20 scopes so far.

We've caught this issue when were trying to load few scopes with missing assets mapping in the app config (something like { "input": "libs/common/util-i18n/src/lib/assets", "glob": "**/*", "output": "assets/i18n/common" })

I've debugged this a bit and it looks like the problem is caused by this statement https://github.com/ngneat/transloco/blob/941459e385654aaa62dcfd80ba959c12277e73c1/libs/transloco/src/lib/transloco.service.ts#L768-L772

shaharkazaz commented 1 year ago

@dmitry-stepanenko I see. You are welcome to open a PR for it 👍 I would also appreciate it if you add a reproduction link and not just an explanation so it is easier to see immediately .