[EuiDataGrid] Fix row height not updating dynamically when set to auto#5281
Conversation
a202fb8 to
07ea516
Compare
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_5281/ |
07ea516 to
8214083
Compare
autoauto
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_5281/ |
- if we're not checking for sameHeight in componentDidUpdate, we also likely don't need this anymore, and all dynamic user changes appear to work without this code
- Rename `recalculateRowHeight` to `setAutoRowHeight` - DRY out setAutoRowHeight to be reusable by both the resize observer and during props update (NB: This leads to some repetition with the height being obtained twice, but will not be an issue shortly as I'll be refactoring/removing the cell wrapper observer in a future PR) - Refactor rowHeightUtils.isAutoHeight to accept an undefined rowHeightsOptions
9e7feb2 to
c91cad5
Compare
c91cad5 to
9eb6651
Compare
| // check if we should update cell because height was changed | ||
| if ( | ||
| this.cellRef.current && | ||
| nextProps.getRowHeight && | ||
| nextProps.rowHeightUtils | ||
| ) { | ||
| if ( | ||
| !nextProps.rowHeightUtils?.compareHeights( | ||
| this.cellRef.current.offsetHeight, | ||
| nextProps.getRowHeight(nextProps.rowIndex) | ||
| ) | ||
| ) { | ||
| return true; | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Quick walkthrough of changes:
-
0eab3ab is the primary workaround @chandlerprall proposed and @VladLasitsa had in his draft PR
-
(this code diff) a553005 removes height check logic from
shouldComponentUpdateas well. I figured if we aren't checking for same height, it makes sense to remove this code also to reduce extra updates. When I tested with auto height I did not see any issues or problems with height not updating when it should (I tested sorting, density, and hiding/reordering columns). -
Some optional proposed refactors: 6b870fd
- I DRY'd it out so that both the ResizeObserver and props change could call the same method. This leads to some repetition with the height being obtained twice in the observer, but it will not be an issue for long as I'll be refactoring/removing the cell wrapper observer in the row height switcher PR (it does not appear to be doing anything)
- I refactored rowHeightUtils.isAutoHeight to accept an undefined rowHeightsOptions
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_5281/ |
chandlerprall
left a comment
There was a problem hiding this comment.
Found one logic issue and another change to revert, but all of the examples are working great!
- occurs if the `defaultHeight` is auto but a specific `rowHeights` line override is not auto TODO: Write a unit test for this in the future
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_5281/ |
|
Weird unit test outcome, jenkins test this |
chandlerprall
left a comment
There was a problem hiding this comment.
Changes LGTM! Let's see if @VladLasitsa finds anything with the Kibana usage 🤞
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_5281/ |
…tsOptions changes
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_5281/ |
970e4b9 to
67d27af
Compare
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_5281/ |
|
I think the last commit (which removes |
I see problem: when we hide column cell heights are not recalculating. |
|
Created a PR (cee-chen#3) against this branch with a proposed fix to update row height on column removal. |
|
@chandlerprall Ha, you read my mind - that was almost exactly the approach I was going to try :) |
chandlerprall
left a comment
There was a problem hiding this comment.
Changes LGTM, tested in many ways and locations
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_5281/ |
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_5281/ |
|
OK, this time with feeling: one last QA round and if we haven't found anything, I think this should be good to go :) I tested with sorting, reordering, hiding, density on EUI docs, and with auto on/off on the Kibana deployed instance, and everything was working for me 🤞 |
…to` (elastic#5281) * Remove isHeightSame check * Remove same height check from shouldComponentUpdate - if we're not checking for sameHeight in componentDidUpdate, we also likely don't need this anymore, and all dynamic user changes appear to work without this code * [Proposed refactors] - Rename `recalculateRowHeight` to `setAutoRowHeight` - DRY out setAutoRowHeight to be reusable by both the resize observer and during props update (NB: This leads to some repetition with the height being obtained twice, but will not be an issue shortly as I'll be refactoring/removing the cell wrapper observer in a future PR) - Refactor rowHeightUtils.isAutoHeight to accept an undefined rowHeightsOptions * Improve unit tests * Add changelog entry * [PR feedback] Fix `isAutoHeight` false positive - occurs if the `defaultHeight` is auto but a specific `rowHeights` line override is not auto TODO: Write a unit test for this in the future * [PR feedback/Discover testing] Trigger component update when rowHeightsOptions changes * [cleanup] Remove now-unused compareHeights util + clean up mock rowHeightUtils as well * [revert] rename setAutoRowHeight back to recalculateRowHeight - lineCount in elastic#5284 will shortly be using the row height cache in addition to auto, so I'm making the fn name less specific again * Add enqueue/timeout to recalculateRowHeight updates - to avoid race conditions with cache being cleared * Remove clearHeightsCache completely * Unset row+column height values on unmount (elastic#3) * Add unit test for new unsetRowHeight + add optional isAutoHeight check * Remove hidden columns from row height cache * Early return in getRowHeight Co-authored-by: Chandler Prall <chandler.prall@gmail.com>
Summary
This PR fixes an issue reported by the Discover team when any props (they tested with columns, I ran into this when changing
rowHeightOptionsdynamically) change onEuiDataGridCell.It essentially removes several performance APIs in favor of updating the heights cache more aggressively/frequently to get behavior working as expected:
isHeightSameclearHeightsCacheBefore
before.mp4
After
fix.mp4
QA
Checklist
- [ ] Check against all themes for compatibility in both light and dark modes- [ ] Checked in mobile- [ ] Props have proper autodocs and playground toggles- [ ] Added documentation- [ ] Checked Code Sandbox works for any docs examples- [ ] Checked for breaking changes and labeled appropriately- [ ] Checked for accessibility including keyboard-only and screenreader modes