Repository navigation
refactor: avoid unnecessary re-renders on virtualizer size change - #5650
Merged
Merged
Conversation
…size-change-renders
vursen
reviewed
Mar 13, 2023
|
Kudos, SonarCloud Quality Gate passed!
|
vursen
approved these changes
Mar 13, 2023
This was referenced Mar 11, 2024
Closed
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.








Description
Changing the virtualizer's
sizeshould 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
_itemsChangediniron-list-core, which in turn would reset the scroll position to 0. To mitigate this, there is a mechanism, based onscrollToIndex, 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
_itemsChangedAPI once on init, and any following size change can be handled just by updating the_virtualCountproperty directly. Since the scroll position is at 0 initially and updating_virtualCountdoesn't lose the scroll position, we can remove the workaround for restoring the scroll position altogether.Type of change
Performance enhancement