Skip to content

Commit 80acf79

Browse files
committed
fix(cdk/scrolling): unsubscribe from scrolled stream when viewport is destroyed (#27800)
Initially the virtual scroll viewport was written under the assumption that it is the scrollable and that it doesn't need to unsubscribe from its `elementScrolled` stream, because it'll be completed on destroy. This might not be the case if a `CdkVirtualScrollableElement` is provided and the viewport might be destroyed without the scrollable being destroyed. These changes add a `takeUntil` to avoid any potential leaks. Fixes #27799. (cherry picked from commit 31187ab)
1 parent a79fae4 commit 80acf79

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/cdk/scrolling/virtual-scroll-viewport.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,10 @@ export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements On
236236
// there are multiple scroll events in the same frame we only need to recheck
237237
// our layout once.
238238
auditTime(0, SCROLL_SCHEDULER),
239+
// Usually `elementScrolled` is completed when the scrollable is destroyed, but
240+
// that may not be the case if a `CdkVirtualScrollableElement` is used so we have
241+
// to unsubscribe here just in case.
242+
takeUntil(this._destroyed),
239243
)
240244
.subscribe(() => this._scrollStrategy.onContentScrolled());
241245

0 commit comments

Comments
 (0)