Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Datagrid] Fix rowHeightOption: auto datagrid calculation issue #8251

Merged
merged 6 commits into from
Feb 4, 2025

Conversation

kqualters-elastic
Copy link
Contributor

@kqualters-elastic kqualters-elastic commented Dec 19, 2024

Summary

Resolves #8245

The useUnconstrainedHeight hook used by datagrid has I think a subtle bug in it around auto height rows, in cases where the row height is 'auto' for all the rows in the table, and when datagrid is aware of them early in the multiple renders it uses to settle on a height, the returned value of this hook, an integer representing the height of the datagrid if it were rendered completely in full is returned as a number based on just the header row height, as described in the issue above. The reason for this, I believe, is because RowHeightUtils.getRowHeightOption will return not always a number, but sometimes the string 'auto' as well. That causes the if at https://github.com/elastic/eui/blob/main/packages/eui/src/components/datagrid/utils/grid_height_width.ts#L137 to be true, and as this is the first time we are attempting to determine the height of this row, the heightsCache of the RowHeightUtils class (these really desperately need to be converted to hooks, and a lot of these problems will disappear) returns 0 for all rows when calling getRowHeight, but we increment the knownRowCount anyway, and the result is this bug. The fix in this PR seems to be the most minimal way to fix this, however I think refactoring the class based utils that revolve around EuiDataGridRowHeightOption/EuiDataGridRowHeightsOptions would be best long term, as now multiple unneeded re-renders are forced from callbacks to force checks like useUnconstrainedHeight to be correct, which is bad for performance, but also calculations that happen outside of the React lifecycle, like with the RowHeightUtils class, unexpectedly do not happen at all in some cases, leading to bugs like this. A well done custom hooks approach could solve both problems at once. I have a branch somewhere with EuiDataGridCell converted from a class based component to a functional one to enable this I think.

QA

Remove or strikethrough items that do not apply to your PR.

General checklist

  • Browser QA
    • Checked in both light and dark modes
    • Checked in mobile
    • Checked in Chrome, Safari, Edge, and Firefox
    • Checked for accessibility including keyboard-only and screenreader modes
  • Docs site QA
  • Code quality checklist
  • Release checklist
    • A changelog entry exists and is marked appropriately.
    • If applicable, added the breaking change issue label (and filled out the breaking change checklist)
  • Designer checklist
    • If applicable, file an issue to update EUI's Figma library with any corresponding UI changes. (This is an internal repo, if you are external to Elastic, ask a maintainer to submit this request)

@kqualters-elastic kqualters-elastic requested a review from a team as a code owner December 19, 2024 03:57
@kqualters-elastic
Copy link
Contributor Author

If anyone is interested https://github.com/kqualters-elastic/eui/tree/row-height-debug has console.logs in the places where you can see the calculation fail, adding a height of 0 to the unconstrained height state, and then (incorrectly) incrementing the knownRowCount. For reproducing, happened immediately on my OSX laptop, on Windows desktop, I had to mess with the zoom level of the browser + the size of the window in order to trigger the bug.

@kqualters-elastic
Copy link
Contributor Author

The failing test is https://github.com/elastic/eui/blob/main/packages/eui/src/components/datagrid/data_grid.spec.tsx#L66 and is probably a bad test IMO. The test is not measuring the unconstrained height from the useUnconstrainedHeight hook, but finalHeight from useFinalGridDimensions. That hook has a height state that would have to be destroyed, or set to 0 at some point, so that this ternary uses unconstrainedHeight

  const finalHeight = isFullScreen
    ? fullScreenHeight
    : height || unconstrainedHeight;

and I think the only reason it passes is because in one of the calculation loops, all heights are 0, similar to the bug in a way.

@acstll
Copy link
Contributor

acstll commented Dec 19, 2024

I can confirm this fixes the original bug where the data grid collapses to 0 (#8245)

I also found a hardcoded height in Storybook, namely in EuiDataGrid / rowHeightsOptions (prop) / Auto, that would be no longer needed:

height={419} // Required by webkit browsers to not render with 0 height. TODO: Investigate why, this is likely a bug


@kqualters-elastic thanks a lot for opening this and sharing your thoughts!

Regarding the test mentioned above, I still need to run it and understand it 🙏 …but I'm guessing here (with the bug fixed) it's failing, and it was passing before but actually asserting the wrong behaviour, correct? — what would you do about it in relation to this PR?

@acstll
Copy link
Contributor

acstll commented Dec 19, 2024

Locally for me computes a new unconstrained height when switching to auto height is passing, but accounts for a horizontal scrollbar is failing… 🤔

@kqualters-elastic
Copy link
Contributor Author

Locally both are passing for me 😂

@acstll
Copy link
Contributor

acstll commented Dec 23, 2024

Locally both are passing for me 😂

for me as well now haha, the one with the horizontal scrollbar needs a particular system setting while running locally!

This 1-liner fix looks good for me!

I would only create a new issue to investigate/address:

Let's wait for the team 🙂

@acstll
Copy link
Contributor

acstll commented Jan 9, 2025

This 1-liner fix looks good for me!

after seeing how cypress fails for React 16 and 17, I think this needs another look.

I can confirm the computes a new unconstrained height when switching to auto height test fails for React 16 and 17 (it does not always does in Open mode!).

main

On main, it passes for all 3 React versions and the height is the expected, though there's a small detail that changes (below):

React version assertion visually correct?
18 expected 256 to be above 0 ⚠️ yes
17 expected 256 to be above 184 yes
16 expected 256 to be above 184 yes
Screenshot 2025-01-09 at 12 10 46

this branch

On this branch, it passes for React 18 only, and the height is not the expected:

React version assertion visually correct?
18 expected 184 to be above 0 no
17 expected 184 to be above 102 (flaky) no
16 expected 184 to be above 184 (flaky) no
Screenshot 2025-01-09 at 12 11 01

I guess we need to figure out whether the test needs some adjustment or the fix is not good enough?

@tkajtoch
Copy link
Member

I'm working on getting these tests fixed, and if there are no other blockers, we should be able to get it merged this week

@tkajtoch tkajtoch removed their assignment Jan 21, 2025
@logeekal
Copy link
Contributor

I'm working on getting these tests fixed, and if there are no other blockers, we should be able to get it merged this week

Hey @tkajtoch ,

Let us know if you need any assistance from our side in getting these tests fixed.

@mbudge
Copy link

mbudge commented Jan 29, 2025

The only way to prevent bugs in the SIEM is if someone opens the alerts page in all supported web-browsers before doing a new release.

This was someone all customers were raising at the engineering all hands in Prague last year.

@logeekal
Copy link
Contributor

The only way to prevent bugs in the SIEM is if someone opens the alerts page in all supported web-browsers before doing a new release.

Thanks @mbudge for your revert. We can do the testing but wanted to confirm if anymore changes are required.

One problem with this kind of bug is it is not 100% reproducible so that always leaves room for error. But Security solution will be happy to test it.

@mbudge
Copy link

mbudge commented Jan 30, 2025

The only way to prevent bugs in the SIEM is if someone opens the alerts page in all supported web-browsers before doing a new release.

Thanks @mbudge for your revert. We can do the testing but wanted to confirm if anymore changes are required.

One problem with this kind of bug is it is not 100% reproducible so that always leaves room for error. But Security solution will be happy to test it.

We have at least 3 different users working in 3 different work environments on 2 browsers affected. Pretty sure someone manually checking the page is working before allowing a new release would mitigate the risk. Automated testing is good but has it's limitations.

@tkajtoch tkajtoch self-assigned this Feb 4, 2025
@tkajtoch
Copy link
Member

tkajtoch commented Feb 4, 2025

To speed things up, I'm going to comment out the flaky tests in this PR and address them separately. It seems that the fix works flawlessly for real users

@kibanamachine
Copy link

Preview staging links for this PR:

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @tkajtoch

Copy link
Member

@tkajtoch tkajtoch left a comment

Choose a reason for hiding this comment

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

Tested locally in EUI and Kibana on main and eui-theme/borealis. Everything works as expected. LGTM

@tkajtoch tkajtoch merged commit af189da into elastic:main Feb 4, 2025
5 checks passed
tkajtoch added a commit to tkajtoch/eui that referenced this pull request Feb 5, 2025
@mbudge
Copy link

mbudge commented Feb 12, 2025

Event rendered view is still broken in chrome in 8.16.4.

delanni pushed a commit to elastic/kibana that referenced this pull request Feb 13, 2025
`99.1.0-borealis.0` ⏩ `99.2.0-borealis.0`

[Questions? Please see our Kibana upgrade
FAQ.](https://github.com/elastic/eui/blob/main/wiki/eui-team-processes/upgrading-kibana.md#faq-for-kibana-teams)

---

## [`v99.2.0`](https://github.com/elastic/eui/releases/v99.2.0)

- Changed `EuiFieldText` styles to prioritize `disabled` styling over
`readonly`. ([#8271](elastic/eui#8271))
- Added `plugs` and `web` glyphs to `EuiIcon`
([#8285](elastic/eui#8285))
- Update `title` on `EuiColorPalettePickerPaletteProps` to be optional
([#8289](elastic/eui#8289))

**Bug fixes**

- Fixed an issue with EuiDataGrid with auto row height resulting in a
table of 0 height ([#8251](elastic/eui#8251))
- Fixed `disabled` behavior of `EuiFieldText` to prevent input changes.
([#8271](elastic/eui#8271))

**Borealis changes**

- [Visual Refresh] Provide hooks for color palette functions
([#8284](elastic/eui#8284))
- [Visual Refresh] Make Borealis default theme in EUI
([#8288](elastic/eui#8288))

---

As you can probably tell, there are plenty of updated tests and
snapshots this time around. They are the result of the following:

1. We've updated the default theme in `@elastic/eui` v99.2.0 to
Borealis, which led to kibana tests using `renderWithTheme`,
`mountWithTheme`, and other utility functions that wrap the tested
component in `<EuiThemeProvider>` to switch to the correct, new color
values. With this change, all tests should now use Borealis, regardless
of the testing framework or its configuration.
2. Because of the default theme change in EUI, some class name hash
fragments (e.g., `css-`**`wprskz`**`-euiButtonIcon-xs-empty-primary`)
regenerated.

Most Borealis-related changes in this PR are test env only and have no
impact on what users see when using Kibana.

---------

Co-authored-by: Elastic Machine <[email protected]>
JoseLuisGJ added a commit to JoseLuisGJ/kibana that referenced this pull request Feb 13, 2025
`99.1.0-borealis.0` ⏩ `99.2.0-borealis.0`

[Questions? Please see our Kibana upgrade
FAQ.](https://github.com/elastic/eui/blob/main/wiki/eui-team-processes/upgrading-kibana.md#faq-for-kibana-teams)

---

## [`v99.2.0`](https://github.com/elastic/eui/releases/v99.2.0)

- Changed `EuiFieldText` styles to prioritize `disabled` styling over
`readonly`. ([elastic#8271](elastic/eui#8271))
- Added `plugs` and `web` glyphs to `EuiIcon`
([elastic#8285](elastic/eui#8285))
- Update `title` on `EuiColorPalettePickerPaletteProps` to be optional
([elastic#8289](elastic/eui#8289))

**Bug fixes**

- Fixed an issue with EuiDataGrid with auto row height resulting in a
table of 0 height ([elastic#8251](elastic/eui#8251))
- Fixed `disabled` behavior of `EuiFieldText` to prevent input changes.
([elastic#8271](elastic/eui#8271))

**Borealis changes**

- [Visual Refresh] Provide hooks for color palette functions
([elastic#8284](elastic/eui#8284))
- [Visual Refresh] Make Borealis default theme in EUI
([elastic#8288](elastic/eui#8288))

---

As you can probably tell, there are plenty of updated tests and
snapshots this time around. They are the result of the following:

1. We've updated the default theme in `@elastic/eui` v99.2.0 to
Borealis, which led to kibana tests using `renderWithTheme`,
`mountWithTheme`, and other utility functions that wrap the tested
component in `<EuiThemeProvider>` to switch to the correct, new color
values. With this change, all tests should now use Borealis, regardless
of the testing framework or its configuration.
2. Because of the default theme change in EUI, some class name hash
fragments (e.g., `css-`**`wprskz`**`-euiButtonIcon-xs-empty-primary`)
regenerated.

Most Borealis-related changes in this PR are test env only and have no
impact on what users see when using Kibana.

---------

Co-authored-by: Elastic Machine <[email protected]>

## Summary

Summarize your PR. If it involves visual changes include a screenshot or gif.

### Checklist

Check the PR satisfies following conditions.

Reviewers should verify this PR satisfies this list as well.

- [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)
- [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials
- [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
- [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations.
- [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed
- [ ] The PR  description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

### Identify risks

Does this PR introduce any risks? For example, consider risks like hard to test bugs, performance regression, potential of data loss.

Describe the risk, its severity, and mitigation for each identified risk. Invite stakeholders and evaluate how to proceed before merging.

- [ ] [See some risk examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)
- [ ] ...
@weronikaolejniczak
Copy link
Contributor

weronikaolejniczak commented Feb 13, 2025

@mbudge I would appreciate more information like the testing path, a video 🙏🏻 I'm following what's said in the issue: #8245 I checked out 8.16 and ran Kibana. This DataGrid has an old picker and when I select "Auto-fit" rows (which is the equivalent to "Auto" in the new picker version) it seems to work perfectly (even without having cherry-picked the commit from this PR):

Screen.Recording.2025-02-13.at.18.04.15.mov

I even checked the EUI version that 8.16 uses - v97.0.0:

Screen.Recording.2025-02-13.at.17.21.16.mov

So this must've been an issue introduced later in the DataGrid.

@kqualters-elastic
Copy link
Contributor Author

@weronikaolejniczak the fun part about this and all related bugs, is that it only happens in some circumstances for some users, as the browser introduces floating point rounding related errors in some situations, that then make their way into the datagrid's code paths when we use getBoundingClientRect and the like. This bug I never ran into on osx using defaults, but saw right away on windows. Was able to reproduce on osx eventually by changing my browser zoom level to 90%/110%, and/or filtering the table down to 1 entry, and switching the row height type. If neither of those work feel free to slack me and I can help, there are a few more ways I know of that can possibly cause this.

@mbudge
Copy link

mbudge commented Feb 13, 2025

Refresh the page and select event rendered view without clicking around.

The density option is not set by default.

Apparently the fix is being backported to 8.16.5

tkajtoch added a commit to tkajtoch/kibana that referenced this pull request Feb 13, 2025
`99.1.0-borealis.0` ⏩ `99.2.0-borealis.0`

[Questions? Please see our Kibana upgrade
FAQ.](https://github.com/elastic/eui/blob/main/wiki/eui-team-processes/upgrading-kibana.md#faq-for-kibana-teams)

---

## [`v99.2.0`](https://github.com/elastic/eui/releases/v99.2.0)

- Changed `EuiFieldText` styles to prioritize `disabled` styling over
`readonly`. ([elastic#8271](elastic/eui#8271))
- Added `plugs` and `web` glyphs to `EuiIcon`
([elastic#8285](elastic/eui#8285))
- Update `title` on `EuiColorPalettePickerPaletteProps` to be optional
([elastic#8289](elastic/eui#8289))

**Bug fixes**

- Fixed an issue with EuiDataGrid with auto row height resulting in a
table of 0 height ([elastic#8251](elastic/eui#8251))
- Fixed `disabled` behavior of `EuiFieldText` to prevent input changes.
([elastic#8271](elastic/eui#8271))

**Borealis changes**

- [Visual Refresh] Provide hooks for color palette functions
([elastic#8284](elastic/eui#8284))
- [Visual Refresh] Make Borealis default theme in EUI
([elastic#8288](elastic/eui#8288))

---

As you can probably tell, there are plenty of updated tests and
snapshots this time around. They are the result of the following:

1. We've updated the default theme in `@elastic/eui` v99.2.0 to
Borealis, which led to kibana tests using `renderWithTheme`,
`mountWithTheme`, and other utility functions that wrap the tested
component in `<EuiThemeProvider>` to switch to the correct, new color
values. With this change, all tests should now use Borealis, regardless
of the testing framework or its configuration.
2. Because of the default theme change in EUI, some class name hash
fragments (e.g., `css-`**`wprskz`**`-euiButtonIcon-xs-empty-primary`)
regenerated.

Most Borealis-related changes in this PR are test env only and have no
impact on what users see when using Kibana.

---------

Co-authored-by: Elastic Machine <[email protected]>
(cherry picked from commit e5958a4)

# Conflicts:
#	src/platform/packages/shared/kbn-unified-data-table/src/components/compare_documents/hooks/__snapshots__/use_comparison_css.test.ts.snap
#	x-pack/solutions/security/packages/kbn-securitysolution-exception-list-components/src/exception_item_card/conditions/entry_content/__snapshots__/entry_content.test.tsx.snap
#	x-pack/solutions/security/plugins/security_solution/public/explore/network/components/embeddables/__mocks__/mock.ts
weronikaolejniczak pushed a commit that referenced this pull request Feb 14, 2025
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.

Eui Datagrid height collapses to 0 when rows as of auto height
8 participants