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

(Multi-scope) Transloco pipe unnecessarily loads dependencies for all scopes in ProviderScope array #394

Open
kaitlynekdahl opened this issue Jan 13, 2021 · 0 comments · May be fixed by #395

Comments

@kaitlynekdahl
Copy link

kaitlynekdahl commented Jan 13, 2021

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[x] Support request
[ ] Other... Please describe:

Current behavior

Currently, for implementations like .selectTranslate() or the Transloco template directives, a scope can be explicitly provided to determine which dependencies to load. This means when using the multi flag for providing scopes, using these functions or directives will only load the necessary translations.

However, the Transloco pipe does not appear to support this distinction, and will map over and load all dependencies for any scopes present in the ProviderScope array, even if only some of those translations are needed for that component.

The source code in question can be found here: https://github.com/ngneat/transloco/blob/master/projects/ngneat/transloco/src/lib/transloco.pipe.ts#L60

For example, on the /lazy-multiple-scopes route in the sample app, if we only want to load dependencies for one scope using the pipe, the network tab will show that additional dependencies for unused scopes have been unnecessarily fetched as well. In the image below, notice that the /assets/i18n/lazy-page/en.json file is requested, even though it is not needed for the component currently rendered.

image

Expected behavior

Transloco pipe should support some mechanism of deriving the key's scope, and only loading translations for that scope.

(PR with suggested behavior linked in comments.)

Minimal reproduction of the problem with instructions

Stackblitz repro: https://stackblitz.com/edit/transloco-pipe-repro?file=src/app/lazy-multiple-scopes/lazy-multiple-scopes.component.html

To see loaded translation files, open the app in a separate window and view the Network tab in the console.

What is the motivation / use case for changing the behavior?

Loading translations for scopes that aren't immediately needed has performance impacts, especially if those translations are coming from an external CMS.

Environment


Angular version: 7.x.x - 9.x.x


Browser:
- [x] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: XX  
- Platform:  

Others:

kaitlynekdahl added a commit to kaitlynekdahl/transloco that referenced this issue Jan 14, 2021
When using multiple scopes, Transloco pipe will derive scope from the key and only load dependencies for that scope.

Closes jsverse#394
@kaitlynekdahl kaitlynekdahl linked a pull request Jan 14, 2021 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant