Skip to content

fix: avoid temporarily clearing the component renderer - #2621

Merged
tomivirkki merged 4 commits into
masterfrom
fix-component-renderer-async
Feb 10, 2022
Merged

tomivirkki merged 4 commits into
masterfrom
fix-component-renderer-async

Conversation

@tomivirkki

@tomivirkki tomivirkki commented Feb 9, 2022 •

Copy link
Copy Markdown
Member

Fixes #2363

The Virtualizer (also used by <vaadin-grid>) uses a native ResizeObserver internally to detect and react to item height changes; in the case of Grid, it observes height changes on the body row (<tr>) elements. Typically it catches row height changes just fine and updates the row positions accordingly.

In this specific case, a <flow-component-renderer> on each row gets assigned a new element reference due to a dynamic data update, resulting in the old element getting removed and the new element getting added asynchronously.

Between these events, (after clearing the content and before the new element gets asynchronously added), the Grid requests the Virtualizer to flush, resulting in the row positions getting recalculated with empty <flow-component-renderer>s in place (meaning, with reduced row height)

After that, the new content is added and the row height increases back to what it was before. One could assume that the ResizeObserver would catch this change in height and fix the row positions. But while all this happens asynchronously, the height actually gets restored exactly to what it was and the delay is fast enough so that the ResizeObserver simply ignores the temporary size change. As a result, the rows end up not getting re-measured and re-positioned with the proper content in place.

This PR changes flow-component-renderer so that it doesn't clear its content while waiting for the new element, but always uses replaceChild if it includes a discarded child element beforehand.

import org.openqa.selenium.WebElement;

import java.util.List;
import java.util.Locale;

@tomivirkki tomivirkki Feb 9, 2022 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Changes to GridDetailsRow tests are a cherry-pick of 57c2b3d and not directly related to this PR

@web-padawan web-padawan left a comment

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.

LGTM. The old logic is indeed confusing, it's better to only clear node once.

@sonarqubecloud

sonarqubecloud Bot commented Feb 9, 2022

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 277 Code Smells

No Coverage information No Coverage information
1.6% 1.6% Duplication

@vaadin-bot

Copy link
Copy Markdown
Collaborator

This ticket/PR has been released with platform 23.0.0.beta2 and is also targeting the upcoming stable 23.0.0 version.

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.

Row height does not adjust after setting new data in Grid when using AppLayout

3 participants