Skip to content

Commit 41be069

Browse files
crisbetommalerba
authored andcommitted
fix(scrolling): complete ScrollDispatcher.scrolled on destroy (#10794)
Currently we stop emitting to `scrolled` once the provider is destroyed, however this can still leave some subscriptions hanging. These changes will also complete the `scrolled` subject.
1 parent 7484321 commit 41be069

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/cdk/scrolling/scroll-dispatcher.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,17 @@ describe('Scroll Dispatcher', () => {
9090

9191
expect(spy).toHaveBeenCalledTimes(1);
9292
});
93+
94+
it('should complete the `scrolled` stream on destroy', () => {
95+
const completeSpy = jasmine.createSpy('complete spy');
96+
const subscription = scroll.scrolled(0).subscribe(undefined, undefined, completeSpy);
97+
98+
scroll.ngOnDestroy();
99+
100+
expect(completeSpy).toHaveBeenCalled();
101+
102+
subscription.unsubscribe();
103+
});
93104
});
94105

95106
describe('Nested scrollables', () => {

src/cdk/scrolling/scroll-dispatcher.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ export class ScrollDispatcher implements OnDestroy {
109109
ngOnDestroy() {
110110
this._removeGlobalListener();
111111
this.scrollContainers.forEach((_, container) => this.deregister(container));
112+
this._scrolled.complete();
112113
}
113114

114115
/**

0 commit comments

Comments
 (0)