Skip to content

fix(cdk/scrolling): fixed-size-virtual-scroll wrong range and position when items length changes and current scroll is greater than new data length #19578

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

Conversation

albyrock87
Copy link
Contributor

FixedSizeVirtualScroll rendered range is not correct when going from a large list to a smaller list.

ezgif-4-afef96a7a7ff

I've checked MR #19030 by @crisbeto with the modified test case but it fails anyway.

One of the main problems is in firstVisibleIndex that it's not correct anymore when the list shrinks to a size smaller then the current scroll position, in fact the following code causes newRange.end < newRange.start:

        if (expandEnd > 0) {
          newRange.end = Math.min(dataLength, newRange.end + expandEnd);
          newRange.start = Math.max(0,
              Math.floor(firstVisibleIndex - this._minBufferPx / this._itemSize));
        }

Unit test changes:

  • Removed a wrong triggerScroll(viewport) on should handle dynamic item array: user doesn't need to scroll the view to see what changed
  • Added some style to test cases to debug easily
  • Added a test to check no-regression with the new code

Fixes #19029

…n when items length changes and current scroll is greater than new data length
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jun 9, 2020
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.

Looks good, thanks for the fix!

@mmalerba mmalerba added lgtm action: merge The PR is ready for merge by the caretaker P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: patch This PR is targeted for the next patch release labels Jun 19, 2020
@jelbourn jelbourn merged commit 1d6ae58 into angular:master Jun 29, 2020
jelbourn pushed a commit that referenced this pull request Jun 29, 2020
…n when items length changes and current scroll is greater than new data length (#19578)

* fix(cdk/scrolling): fixed-size-virtual-scroll wrong range and position when items length changes and current scroll is greater than new data length

* Added comments and fixed behavior when new dataLength matches current range end
@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 30, 2020
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 cla: yes PR author has agreed to Google's Contributor License Agreement P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CdkVirtualScrollViewport rendered range is not correct when going from a large list to a smaller list
4 participants