Scrollbar jumping in CdkVirtualScrollViewport with variable item sizes
0 reputation · 01 Apr 2022, 18:50 UTC
Dynamic Content Rendering in CDK Virtual Scroll
The CdkVirtualScrollViewport is utilized to manage large datasets by rendering only the visible subset of items. While the fixed-size strategy provides stable performance, implementing variable item sizes introduces complexity in how the viewport calculates the total scrollable area and current offset.
When items have dynamic heights based on content, the viewport must predict the size of non-rendered elements to maintain a consistent scrollbar position. Inaccurate size predictions can lead to visual instability during rapid scrolling.
What is the recommended approach to synchronize the DataSource with the viewport strategy to prevent scrollbar jumping? How can the viewport be notified of item size changes after the initial render to ensure the scroll offset remains accurate?