bug(cdkTable & mat-table): virtual scrolling shifting issues introduced in 21.1

未关闭
#32,715 48 条评论 27 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
冷清
领域
frontend

调研方向

首先比较 v21.0 和 v21.1.1 的 StackBlitz 表格示例,尤其是 virtual-scroll 的行为和 DataSource 示例。在第三个复现中,取消 table-virtual-scroll-example.component.ts 中异步实现的注释,并观察滚动时的 collectionViewer.onViewChange range.end。完成的标准是 mat-table 和 cdkTable 滚动时不会发生偏移,并且无限滚动不会重复获取页面。

由索引模型根据 Issue 内容生成。

描述

area: cdk/scrolling area: cdk/table P2
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

21.0.0

Description

In version v20.0.0 we had used a custom virtual scrolling strategy to allow tables with sticky headers. Upgrade to 21.0.0 broke the custom scrolling strategy implementation we have used so we decided to look for alternatives. Luckily, It seems that 21.0 also introduced support for tables with sticky header (or was introduced earlier, I am actually not sure which version added support), unfortunately, version 21.1 seems to introduce a bug which makes the scrolling shift around.

The bug can be seen in the example provided in the Table documentation as well. The documentation is still running on 21.0.0 but if you upgrade the example to 21.1.1, you can start seeing the buggy behavior when scrolling.

Scrolling seems to be fixed when itemSize is set to 0, however, in infinite scrolling implementations using DataSource that rely on collectionViewer.onViewChange range.end, it will continuously fetch the next page since range.end will always be the max value (3rd stackblitz link in the reproduction links has an async implementation mocked example that can be tested if uncommented in table-virtual-scroll-example.component.ts in constructor)

Example provided is on mat-table but cdkTable's behavior is the same if not worse

Reproduction

StackBlitz link:
v21.0 (original example on version 21.0): https://stackblitz.com/edit/dfp4dgn5?file=src%2Fexample%2Ftable-virtual-scroll-example.ts&startScript=start
v21.1.1 (original example but on version 21.1.1): https://stackblitz.com/edit/6wi4nsxd?file=src%2Fexample%2Ftable-virtual-scroll-example.ts&startScript=start
v21.1.1 with DataSource: https://stackblitz.com/edit/gt9emjwr?file=src%2Fexample%2Ftable-virtual-scroll-example.ts (much more noticeable in this example)

Steps to reproduce:

  1. Scroll around using the scroll wheel (also happens when you drag around the scrollbar thumb especially visible in tables with small amount of rows)
  2. 3rd link has an infinite scrolling implementation that can be tested if uncommented in table-virtual-scroll-example.component.ts's constructor
Expected Behavior

The table should scroll correctly without shifting around

Actual Behavior

Scrolling shifts around, some cases making it impossible to even scroll back up once you go all the way down and some cases scrolls upwards when scrolling down

Environment
  • Angular: 21.1.1
  • CDK/Material: 21.1.1
  • Browser(s): Chrome
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows & macOS
主要语言
TypeScript
星标
25k
派生
6.9k
平均合并
2 天 7 小时
30 天内合并 PR
83

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

angular/components 的其他 Issue

查看 angular/components 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。