8000 fix(core): unregister `onDestroy` in `outputToObservable` (#61882) · angular/angular@1cd23be · GitHub
[go: up one dir, main page]

Skip to content

Commit 1cd23be

Browse files
arturovtpkozlowski-opensource
authored andcommitted
fix(core): unregister onDestroy in outputToObservable (#61882)
We should remove the `onDestroy` listener once subscription is unsubscribed because components might not be destroyed yet, but they still would capture subscribers. PR Close #61882
1 parent 59eb720 commit 1cd23be

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

packages/core/rxjs-interop/src/output_to_observable.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ export function outputToObservable<T>(ref: OutputRef<T>): Observable<T> {
2424
// Complete the observable upon directive/component destroy.
2525
// Note: May be `undefined` if an `EventEmitter` is declared outside
2626
// of an injection context.
27-
destroyRef?.onDestroy(() => observer.complete());
27+
const unregisterOnDestroy = destroyRef?.onDestroy(() => observer.complete());
2828

2929
const subscription = ref.subscribe((v) => observer.next(v));
30-
return () => subscription.unsubscribe();
30+
return () => {
31+
subscription.unsubscribe();
32+
unregisterOnDestroy?.();
33+
};
3134
});
3235
}

0 commit comments

Comments
 (0)
0