-
-
Notifications
You must be signed in to change notification settings - Fork 198
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
feat: pipe only loads necessary dependencies #395
base: master
Are you sure you want to change the base?
feat: pipe only loads necessary dependencies #395
Conversation
When using multiple scopes, Transloco pipe will derive scope from the key and only load dependencies for that scope. Closes jsverse#394
@kaitlynekdahl Thanks for the very detailed issue 🙂 |
Hey @shaharkazaz, a specific scenario that I've seen is the need for all scopes to be imported at the root module level so that services that have I think your assumption is valid in the case that an app is only using lazily-loaded modules without singleton services, though. Are you thinking the above scenario should be handled differently? |
@kaitlynekdahl Hey! sorry for the late response. If I misunderstood something, please feel free to share a more detailed explanation regarding your app's needs! |
I'd like this feature as well. Currently I have components which may use different scopes inside (in order to not duplicate these strings), But adding all these scopes for each component ( / module) just takes too much time (the more components / module you split up the more scopes you need to add on each module) Thats why I also just list all scopes in the TranslocoRootModule - and then use the strings everywhere I want. But that way it'll load all scopes on the first resolve which you might not need (yet) This might be outside of the norm of Transloco but once you need to split up components into more modules (in order to create smaller bundles) the current way just adds more / repetitive work of adding/checking all scopes that are needed per component. |
@kaitlynekdahl, this will cause a side effect. For example, if you have multiple components with different scopes that should be rendered simultaneously, there could be a delay between them depending on the latency. If you are not worried about this side effect, we'll accept a modified PR where your code is optional. |
Any update on this? :) |
@negue waiting for @kaitlynekdahl to address my comments 🙂 |
@shaharkazaz sorry for the even slower response! When you say there could be a delay between the components, are you saying there'd be a flash of untranslated content while the scopes are resolved synchronously? Also for making the code optional, are you thinking there'd be a flag passed into the Example usage:
Then we can use the |
When using multiple scopes, Transloco pipe will derive scope from the key and only load dependencies for that scope.
Closes #394
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: #394
When using
multi
flag, Transloco flag will map over and load dependencies for all scopes in the ProviderScope array, even if those fetched translations aren't needed for the view currently rendered. This might result in performance issues due to unnecessary API calls.For example, the following component from the sample would only need translations for the
admin-page
scope, but the network tab shows that an unneeded call was also made forlazy-page
translations:What is the new behavior?
The Transloco pipe should derive the scope in question from the key passed in, then determine which scope to resolve by searching the ProviderScope array for a matching scope or alias name.
After these changes, we can see that the unneeded call for
lazy-page
translations is no longer made:Does this PR introduce a breaking change?
Other information