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

[8.x] [Unified Data Table] Prevent `undefined` errors when row accessed via `rows[rowIndex]` (#193791) #193908

Merged
merged 1 commit into from
Sep 24, 2024

Conversation

kibanamachine
Copy link
Contributor

Backport

This will backport the following commits from main to 8.x:

Questions ?

Please refer to the Backport tool documentation

… `rows[rowIndex]` (elastic#193791)

## Summary

This PR fixes an issue present in 8.15, but which no longer exists after
later refactoring, where saved search panels (possibly only ES|QL
panels? It was hard to nail down since involved a race condition) could
fail in dashboards when adding Unified Search filters that reduce the
number of results in the grid.

I'm still not 100% sure what the source of the issue was since it
involved a race condition (didn't fail consistently for me locally) and
internal EUI data grid code, but I have a hunch. The `undefined` errors
occurred when trying to access a row by index from `DataTableContext` in
certain cell renderers during the first render after search results had
changed. I believe what was happening was the change to
`DataTableContext` triggered a re-render of the cells before EUI data
grid internally updated its state, resulting in attempts to access rows
from within the cell renderers that no longer existed in the updated
`DataTableContext`, and causing `undefined` reference errors.

I'm making these changes in `main` instead of `8.15` directly because
the updated approach is generally a safer way to retrieve rows and
prevent similar issues in the future. Previously we added `rows` to
`DataTableContext` and retrieved a single row by index using bracket
notation, which can potentially return `undefined`, but TypeScript does
not protect against it for us. Instead I've updated `DataTableContext`
with a `getRowByIndex` method that correctly returns `DataTableRecord |
undefined` and forces consumers to explicitly handle the `undefined`
scenario.

The PR will require some manual backporting to 8.15 since some things
have changed since then, but it shouldn't be difficult.

### Checklist

- [ ] 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/packages/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
- [x] [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
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [ ] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [ ] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
- [ ] 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 renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [ ] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)

### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

(cherry picked from commit 6ff0791)
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
cloudSecurityPosture 496.7KB 497.0KB +322.0B
discover 812.4KB 812.7KB +327.0B
esqlDataGrid 153.0KB 153.3KB +327.0B
securitySolution 20.4MB 20.4MB +1.6KB
slo 853.7KB 854.0KB +322.0B
total +2.8KB

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @davismcphee

@kibanamachine kibanamachine merged commit bdfccd2 into elastic:8.x Sep 24, 2024
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants