Skip to content

refactor: avoid unnecessary re-renders on virtualizer size change - #5650

Merged
tomivirkki merged 3 commits into
mainfrom
refactor/virtualizer-size-change-renders
Mar 13, 2023
Merged

tomivirkki merged 3 commits into
mainfrom
refactor/virtualizer-size-change-renders

Conversation

@tomivirkki

@tomivirkki tomivirkki commented Mar 10, 2023 •

Copy link
Copy Markdown
Member

Description

Changing the virtualizer's size should never cause element updates if the size change doesn't affect any visible elements. There's actually a test case for it also, but it failed to catch the case where the user might have scrolled the virtualizer manually before the size change.

The current size change implementation always invokes the _itemsChanged in iron-list-core, which in turn would reset the scroll position to 0. To mitigate this, there is a mechanism, based on scrollToIndex, to restore the scroll position after the size change back to what it was before.

Due to this workaround, the virtualizer ended up in seemingly the same scroll position, but sometimes having items in the viewport represented by different DOM elements than before the size change so an update was necessary to have the element content up-to-date.

After some investigation, it turns out we only need to use the _itemsChanged API once on init, and any following size change can be handled just by updating the _virtualCount property directly. Since the scroll position is at 0 initially and updating _virtualCount doesn't lose the scroll position, we can remove the workaround for restoring the scroll position altogether.

Type of change

Performance enhancement

@sonarqubecloud

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@tomivirkki
tomivirkki merged commit 1cf96ee into main Mar 13, 2023
@tomivirkki
tomivirkki deleted the refactor/virtualizer-size-change-renders branch March 13, 2023 11:03
vursen added a commit that referenced this pull request Mar 13, 2024
vursen added a commit that referenced this pull request Mar 19, 2024
…ange (#5650)" (#7205)

Co-authored-by: ugur-vaadin <ugur@vaadin.com>
vaadin-bot pushed a commit that referenced this pull request Mar 19, 2024
…ange (#5650)" (#7205)

Co-authored-by: ugur-vaadin <ugur@vaadin.com>
vursen added a commit that referenced this pull request Mar 19, 2024
…ange (#5650)" (#7205) (#7236)

Co-authored-by: Sergey Vinogradov <mr.vursen@gmail.com>
Co-authored-by: ugur-vaadin <ugur@vaadin.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants