Skip to content

Commit e81ea0c

Browse files
arturovtpkozlowski-opensource
authored andcommitted
fix(core): unregister onDestroy in outputToObservable (angular#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 angular#61882
1 parent eb20c1f commit e81ea0c

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy