You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(transloco): prevent loading translations when injector is destroyed
This avoids potential memory leaks and ensures correct behavior in reactive streams
(e.g. switchMap) by returning EMPTY, which completes immediately.
Use-case:
- If load() is triggered via an observable (like within switchMap), and the service
has already been destroyed (e.g. due to app shutdown, route unload, or SSR teardown),
continuing execution would:
- Create unnecessary subscriptions and pending async operations (like network calls).
- Risk caching invalid/partial translation data.
- In SSR, could retain memory or even leak state between requests.
Returning EMPTY ensures the observable chain completes cleanly without side effects.
Here’s a specific leak scenario this fix prevents:
```js
componentLanguage$.pipe(
switchMap(lang => translocoService.load(lang)),
).subscribe();
```
0 commit comments