mui-x icon indicating copy to clipboard operation
mui-x copied to clipboard

[DataGrid] Fix first row flickering with autoHeight enabled

Open kenanyusuf opened this issue 1 year ago • 1 comments

Fixes the first row flickering when a new, editable row is added to a grid with autoHeight enabled.

Fixes #13270

The problem

1. User adds a new row

Screenshot 2024-08-16 at 14 06 21

2. The new row gets rendered in the correct position, but the original row is hidden

This happens because the newly added editable cell calls .focus() when it mounts. The virtual scroller has a scroll event listener that listens to scroll events in order to recalculate which rows are in view to render. The browser tries to scroll the editable cell into view, and triggers the scroll event callback.

The scroll event handler receives an event.scrollTop position of 52px, and decides that the first row does not need rendering because based on this value, it is out of view. This is what leads to the temporary state of a hidden first row.

Why is this only a problem with autoHeight enabled?

When autoHeight is not enabled, the scroll event listener only fires when the virtual scroller content actually becomes scrollable. This means the editable cell moves into focus and there is no visible flicker.

With autoHeight enabled, the virtual scroller content temporarily overflows when a new row is added whilst it recalculates the virtual scroller content height.

Screenshot 2024-08-16 at 14 06 30

3. The virtual scroller recalculates and re-renders both rows in the correct position

Screenshot 2024-08-16 at 14 06 38

The solution

Disable row virtualization when autoHeight is enabled. Row virtualization has no performance gains when autoHeight is enabled as the list of rows never becomes scrollable. This in turn fixes the issue of the virtual scroller miscalculating which elements are in view.

kenanyusuf avatar Aug 16 '24 13:08 kenanyusuf

Deploy preview: https://deploy-preview-14235--material-ui-x.netlify.app/

Updated pages:

Generated by :no_entry_sign: dangerJS against 501b648c618a56f00ccbad756be5398f513c6c53

mui-bot avatar Aug 16 '24 13:08 mui-bot

Thank you guys for bashing this bug !

Our users will be happy to have this fixed :pray: !!

Luis-Ramirez21x avatar Aug 30 '24 23:08 Luis-Ramirez21x