Skip to content

fix: update scroll height when estimation is maxpages times larger than viewport height - #7200

Closed
ugur-vaadin wants to merge 10 commits into
mainfrom
fix-update-max-pages-value-to-avoid-miscalculating-height
Closed

ugur-vaadin wants to merge 10 commits into
mainfrom
fix-update-max-pages-value-to-avoid-miscalculating-height

Conversation

@ugur-vaadin

@ugur-vaadin ugur-vaadin commented Mar 12, 2024 •

Copy link
Copy Markdown
Contributor

Description

In iron-list-core, the scroller size is updated based on some conditions. For some varying item height combinations, these conditions are not met. This leads to the scroller height not being updated, and causes a grid where all rows should visible not having the correct height at first. Scrolling to the end forces the scroller height to be updated later, which changes the grid height.

This PR adds another condition to the if clause. This way, the scroller height will also be updated when the estimated scroller height is equal or larger than _maxPages * _viewportHeight. The value of _maxPages is constant and set to 1.3 in order to optimize the number of rendered items. The problems do not reproduce with a similar setup anymore.

Fixes #7160

Type of change

  • Bugfix
  • Feature

Checklist

  • I have read the contribution guide: https://vaadin.com/docs/latest/contributing/overview
  • I have added a description following the guideline.
  • The issue is created in the corresponding repository and I have referenced it.
  • I have added tests to ensure my change is effective and works as intended.
  • New and existing tests are passing locally with my change.
  • I have performed self-review and corrected misspellings.

@ugur-vaadin
ugur-vaadin marked this pull request as draft March 12, 2024 17:04
@ugur-vaadin ugur-vaadin changed the title fix: update max pages value to ensure all rows visible with varying heights fix: update scroll height when estimation is maxpages times larger than viewport height Mar 13, 2024
@ugur-vaadin
ugur-vaadin requested a review from tomivirkki March 13, 2024 13:49
@ugur-vaadin
ugur-vaadin marked this pull request as ready for review March 13, 2024 13:49
forceUpdate ||
this._scrollHeight === 0 ||
this._scrollPosition >= estScrollHeight - this._physicalSize ||
estScrollHeight >= this._maxPages * this._viewportHeight ||

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See this note

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. Do you think the solution makes sense in general? I can refactor it into the adapter.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative could be restoring something similar to a removed grid condition to the adapter.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue with the this.grid approach is that I think this.grid in the adapter does not seem to work for a default grid anymore. I am not sure if this is customized for another reason.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the logic to the adapter. It is a little ugly as the overridden iron list function is possibly called twice. However, it should not affect the performance.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding this.grid, I think this block can be removed if I am not missing something.

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

* @override
*/
_updateScrollerSize(forceUpdate) {
super._updateScrollerSize(forceUpdate);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid the extra call if we move this to an else-block?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any call to super._updateScrollerSize updates the estimated scroller size. At that point, the if block would not matter since the _estScrollHeight will have the older estimation.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems that #7205 also fixes this issue

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is interesting. I haven't considered that it would. I don't really know why it could. Probably the re-rendering force updates some values. Do you think we should go with that? If so, I think we still should keep the test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would still need to revisit this if another optimization is introduced to avoid extra renders.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can avoid adding extra complexity if the other PR (perhaps accidentally) also fixes the same issue. Agreed, the test should still be added to make sure the grid keeps working as expected in the future.

@ugur-vaadin

Copy link
Copy Markdown
Contributor Author

Closing in favour of #7205

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Grid with allRowsVisible sizes incorrectly with varying row height

2 participants