bug(cdk/scrolling): The append only mode assumes that scrolling starts at zero and therefore calculates renderedRange incorrectly
- Dominant language
- TypeScript
- Stars
- 25k
- Forks
- 6.8k
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 91
Description
#### Reproduction
Steps to reproduce:
1. Create a virtual scroll container with `appendOnly`
2. Load the virtual scroll container and don't load it from the top
3. The `renderedRange` is wrongly calculated/set
#### Expected Behavior
A virtual scroll container can be loaded at any position without `renderedRange` being set incorrectly.
#### Actual Behavior
The `renderedRange` was set incorrectly once the virtual scroll container was loaded not at the top. I archived this behaviour via the following CSS setting.
```
[cdk-virtual-scroll-viewport] {
overflow-anchor: none;
}
```
#### A possible solution
I was able to solve this issue by overriding the following code at [virtual-scroll-viewport.ts#L292](https://github.com/angular/components/blob/6076801883194f263a5c692797ffc863a8de9771/src/cdk/scrolling/virtual-scroll-viewport.ts#L292)
```diff
if (this.appendOnly) {
- range = {start: 0, end: Math.max(this._renderedRange.end, range.end)};
+ range = {start: Math.min(this._renderedRange.start, range.start), end: Math.max(this._renderedRange.end, range.end)};
}
```
I am not sure if I am missing something. For this reason, I have just opened an issue and no pull request for now.
#### Environment
- Angular: 12.2.5
- CDK/Material: 12.2.5
- Browser(s): Chrome
- Operating System (e.g. Windows, macOS, Ubuntu): macOS
Contributor guide
Research direction
Start in src/cdk/scrolling/virtual-scroll-viewport.ts around the appendOnly range calculation at line 292, then reproduce the issue with a virtual scroll container loaded at a nonzero position. Verify that renderedRange preserves the initially loaded range rather than assuming a start of zero; the work is done when appendOnly behaves correctly for that case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100