angular / angular/components

bug(cdk/scrolling): The append only mode assumes that scrolling starts at zero and therefore calculates renderedRange incorrectly

オープン
#23,578 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
area: cdk/scrolling P3
主要言語
TypeScript
スター
25k
フォーク
6.8k
平均マージ
1日 8時間
マージ済み PR(30日)
91

説明

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

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

src/cdk/scrolling/virtual-scroll-viewport.ts の 292 行目付近にある appendOnly の範囲計算から始め、ゼロ以外の位置で読み込まれた仮想スクロールコンテナで問題を再現します。renderedRange が開始位置をゼロと仮定せず、最初に読み込まれた範囲を保持することを確認します。このケースで appendOnly が正しく動作すれば作業は完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
angular, typescript
領域
frontend
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
55/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。