Commit e31c6f7
committed
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();
```1 parent f3a7829 commit e31c6f7
1 file changed
+10
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| 112 | + | |
112 | 113 | | |
113 | 114 | | |
114 | 115 | | |
| |||
144 | 145 | | |
145 | 146 | | |
146 | 147 | | |
| 148 | + | |
147 | 149 | | |
148 | 150 | | |
149 | 151 | | |
| |||
193 | 195 | | |
194 | 196 | | |
195 | 197 | | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
196 | 206 | | |
197 | 207 | | |
198 | 208 | | |
| |||
0 commit comments