Skip to content

Conversation

MichaelJamesParsons
Copy link
Collaborator

This PR adds an appendOnly input to cdk-virtual-scroll-viewport, which disables view recycling so items remain in the DOM even after they scroll out of view. This can be more performant for scroll viewports that render complex components that may be expensive to remove or insert at the beginning of the list while scrolling up.

Option questions

  • Should the viewport throw if appendOnly changes after initialization? For example, if a user scrolls to the bottom of a list containing 2k items, then enables appendOnly, the viewport will render all 2k items.

@google-cla google-cla bot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jun 15, 2021
@MichaelJamesParsons MichaelJamesParsons added area: cdk/scrolling G This is is related to a Google internal issue labels Jun 15, 2021
@@ -121,3 +121,10 @@ custom strategy by creating a class that implements the `VirtualScrollStrategy`
providing it as the `VIRTUAL_SCROLL_STRATEGY` on the component containing your viewport.

<!-- example(cdk-virtual-scroll-custom-strategy) -->

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's been a while since I've looked at this code, but how is this different to setting the cache size to zero? I was under the impression that if a view can't be cached, it'll be recreated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the difference is that with cache size zero, it won't reuse already created views, but it will remove them from the DOM. The idea with this change is to have a mode where it never removes anything from the DOM, only adds.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the description to clarify this behavior.

Copy link
Contributor

@mmalerba mmalerba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mmalerba mmalerba added action: merge The PR is ready for merge by the caretaker target: minor This PR is targeted for the next minor release labels Jun 16, 2021
@mmalerba mmalerba changed the title feat(cdk/virtual-scroll): add input to disable view recycling in virtual scroll viewport feat(cdk/virtual-scroll): add input to enable append-only mode in virtual scroll viewport Jun 16, 2021
@MichaelJamesParsons MichaelJamesParsons changed the title feat(cdk/virtual-scroll): add input to enable append-only mode in virtual scroll viewport feat(cdk/scrolling): add input to enable append-only mode in virtual scroll viewport Jun 16, 2021
@MichaelJamesParsons
Copy link
Collaborator Author

Updated the commit message to match the new PR title.

@mmalerba mmalerba merged commit 8f052cc into angular:master Jun 18, 2021
@MichaelJamesParsons MichaelJamesParsons deleted the cdk-infinite-scroll branch June 18, 2021 20:33
@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 Jul 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: cdk/scrolling cla: yes PR author has agreed to Google's Contributor License Agreement G This is is related to a Google internal issue target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants