angular / angular/components

bug(cdk-experimetal/scrolling): Every item of input array is rendered initially

Open
#23,996 1 comment 1 reaction 0 assignees View on GitHub
area: cdk/scrolling P2
Dominant language
TypeScript
Stars
25k
Forks
6.8k
Avg merge
1d 8h
Merged PRs (30d)
91

Description

### 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

Initially, before any scrolling occurs; every item of `items` passed to `cdkVirtualFor` is rendered. After scrolling down for a bit (till `translateY` of `.cdk-virtual-scroll-content-wrapper` changes) and scrolling up (even just a bit) the list of rendered elements sharing to only visible elements.

### Reproduction

Could not create stackblitz with `cdk-experimental` nor `angular` v13. Here is an example of what it does in my fairly rudimentary case: https://youtu.be/ILHPaMk2hZU

related code:
```html


```
-----

Steps to reproduce:
1. Create a container and any item template. Fixed height for simplicity is perfect
```

{{item | json}}

```
2. Populate `items` array with 1000 elements
3. View in elements panel, that there is the same number of `div`s as there is of `items`.

### Expected Behavior

I expected only needed elements to be rendered.

### Actual Behavior

Every element of my array is rendered making `cdk-virtual-scroll-viewport` do nothing!

### Environment

Angular CLI: 13.0.3
Node: 14.15.4
Package Manager: npm 7.20.6
OS: win32 x64

Angular: 13.0.2
... animations, cdk, cdk-experimental, common, compiler
... compiler-cli, core, forms, language-service, material
... platform-browser, platform-browser-dynamic, router
... service-worker

Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1300.3
@angular-devkit/build-angular 13.0.3
@angular-devkit/core 13.0.3
@angular-devkit/schematics 13.0.3
@angular/cli 13.0.3
@angular/google-maps 12.1.3
@schematics/angular 13.0.3
rxjs 7.4.0
typescript 4.4.4

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the provided cdkVirtualFor example with 1,000 fixed-height items and inspect the rendered elements before and after scrolling. Trace the cdkVirtualFor and autosize behavior to determine why the initial render includes every item; done means only the needed visible elements are rendered from the start.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
frontend, performance
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.