Skip to content

Conversation

Mr-KRAMA
Copy link
Contributor

This PR fixes the issue where cdk-virtual-scroll-viewport renders visible gaps between items at certain zoom levels or scroll positions.

Problem:
Thin gaps (~0.5px) appear between consecutive rows when using *cdkVirtualFor

Issue occurs due to subpixel rounding in offset calculations

Most noticeable when zooming browser window or at specific scroll positions

Solution:
Added Math.round() to the offset calculation in setRenderedContentOffset()

Ensures all item positions are rounded to whole pixels

Eliminates subpixel gaps while maintaining smooth scrolling

Changes:

Single line change in fixed-size-virtual-scroll.ts

Wraps this._itemSize * newRange.start with Math.round()

Testing
Tested with different zoom levels (300%)

Verified no gaps appear between items during scrolling

Confirmed smooth scrolling behavior is preserved

Fixes #31824

@Mr-KRAMA Mr-KRAMA requested a review from a team as a code owner September 29, 2025 04:03
@Mr-KRAMA Mr-KRAMA requested review from crisbeto and ok7sai and removed request for a team September 29, 2025 04:03
Copy link

google-cla bot commented Sep 29, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@Mr-KRAMA Mr-KRAMA force-pushed the fix/virtual-scroll-subpixel-gaps branch from d4b2a17 to f591920 Compare September 29, 2025 04:11
@crisbeto crisbeto requested a review from mmalerba September 29, 2025 07:32
@mmalerba mmalerba added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release labels Sep 29, 2025
@angular-robot angular-robot bot added the area: docs Related to the documentation label Sep 29, 2025
@Mr-KRAMA Mr-KRAMA requested a review from mmalerba September 29, 2025 16:11
@mmalerba
Copy link
Contributor

@Mr-KRAMA Can you remove the second commit? I think that failure was either a flake or an unrelated issue that can be fixed separately from this PR

@Mr-KRAMA Mr-KRAMA force-pushed the fix/virtual-scroll-subpixel-gaps branch from 210df2c to f591920 Compare September 29, 2025 20:52
@Mr-KRAMA
Copy link
Contributor Author

Mr-KRAMA commented Sep 29, 2025

@mmalerba Thanks for the feedback! I've removed the second commit as requested.

How should I approach the lighthouse audit failure? Should it be a separate PR or is it expected to be handled by maintainers?

@mmalerba mmalerba merged commit 2918e28 into angular:main Sep 30, 2025
41 of 45 checks passed
@mmalerba
Copy link
Contributor

This PR was merged into the repository. The changes were merged into the following branches:

mmalerba pushed a commit that referenced this pull request Sep 30, 2025
…31940)

Co-authored-by: MR-KRAMA <Mr-KRAMA@users.noreply.github.com>
(cherry picked from commit 2918e28)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action: merge The PR is ready for merge by the caretaker area: cdk/scrolling area: docs Related to the documentation target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug(cdk-virtual-scroll-viewport): renders gaps between items
2 participants