Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(CdkVirtualScrollViewport): no unsubscribe from scrolling after destroy #27799

Closed
1 task
RealOFF opened this issue Sep 17, 2023 · 1 comment · Fixed by #27800
Closed
1 task

bug(CdkVirtualScrollViewport): no unsubscribe from scrolling after destroy #27799

RealOFF opened this issue Sep 17, 2023 · 1 comment · Fixed by #27800
Assignees
Labels
area: cdk/scrolling P4 A relatively minor issue that is not relevant to core functions

Comments

@RealOFF
Copy link

RealOFF commented Sep 17, 2023

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

CdkVirtualScrollViewport subscribes to this.scrollable.elementScrolled() but does not unsubscribe from it. In most cases, when you are not using cdkVirtualScrollingElement, this will not be any problem because scrollable unsubscribes when destroyed, but when we use cdkVirtualScrollingElement and the cdk-virtual-scroll-viewport element is mounted/unmounted from the DOM, there will be unnecessary scroll subscriptions. This subscriptions can lead to some unexpected behaviours.

Reproduction

StackBlitz link: https://stackblitz.com/edit/l1quzt-cwdqhc?file=src%2Fexample%2Fcdk-virtual-scroll-parent-scrolling-example.html
Steps to reproduce:

  1. Click a lot of time on "Toggle show" button.
  2. Setup breakpoint in FixedSizeVirtualScrollStrategy.prototype.onContentScrolled(vendor.js 22253 line).
  3. Scroll content to the bottom.

Expected Behavior

After small scroll the onContentScrolled should be called only one time with this._viewport in FixedSizeVirtualScrollStrategy that equal CdkVirtualScrollViewport instance.

Actual Behavior

After small scroll the FixedSizeVirtualScrollStrategy.prototype.onContentScrolled will be called a lot of time with this._viewport === null in FixedSizeVirtualScrollStrategy.

Environment

  • Angular: 16.2.3
  • CDK/Material: CDK
  • Browser(s): Chrome
  • Operating System (e.g. Windows, macOS, Ubuntu): macOS
@RealOFF RealOFF added the needs triage This issue needs to be triaged by the team label Sep 17, 2023
@RealOFF RealOFF changed the title bug(CdkVirtualScrollViewport): TITLE bug(CdkVirtualScrollViewport): no unsubscribe in scrollable Sep 17, 2023
@RealOFF RealOFF changed the title bug(CdkVirtualScrollViewport): no unsubscribe in scrollable bug(CdkVirtualScrollViewport): no unsubscribe in CdkVirtualScrollViewport Sep 17, 2023
@RealOFF RealOFF changed the title bug(CdkVirtualScrollViewport): no unsubscribe in CdkVirtualScrollViewport bug(CdkVirtualScrollViewport): no unsubscribe from scrolling in CdkVirtualScrollViewport Sep 17, 2023
@RealOFF RealOFF changed the title bug(CdkVirtualScrollViewport): no unsubscribe from scrolling in CdkVirtualScrollViewport bug(CdkVirtualScrollViewport): no unsubscribe from scrolling Sep 17, 2023
@RealOFF RealOFF changed the title bug(CdkVirtualScrollViewport): no unsubscribe from scrolling bug(CdkVirtualScrollViewport): no unsubscribe from scrolling after destroy Sep 17, 2023
@crisbeto crisbeto self-assigned this Sep 18, 2023
@crisbeto crisbeto added P4 A relatively minor issue that is not relevant to core functions area: cdk/scrolling and removed needs triage This issue needs to be triaged by the team labels Sep 18, 2023
crisbeto added a commit to crisbeto/material2 that referenced this issue Sep 18, 2023
… destroyed

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 angular#27799.
crisbeto added a commit that referenced this issue Sep 18, 2023
… 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)
crisbeto added a commit that referenced this issue Sep 18, 2023
… 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.
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Oct 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: cdk/scrolling P4 A relatively minor issue that is not relevant to core functions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants