Skip to content

Commit 31187ab

Browse files
authored
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.
1 parent 2409e70 commit 31187ab

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
@@ -229,6 +229,10 @@ export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements On
229229
// there are multiple scroll events in the same frame we only need to recheck
230230
// our layout once.
231231
auditTime(0, SCROLL_SCHEDULER),
232+
// Usually `elementScrolled` is completed when the scrollable is destroyed, but
233+
// that may not be the case if a `CdkVirtualScrollableElement` is used so we have
234+
// to unsubscribe here just in case.
235+
takeUntil(this._destroyed),
232236
)
233237
.subscribe(() => this._scrollStrategy.onContentScrolled());
234238

0 commit comments

Comments
 (0)