Skip to content

[8.15] [Unified Data Table] Prevent undefined errors when row accessed via rows[rowIndex] (#193791)#193921

Merged
davismcphee merged 1 commit intoelastic:8.15from
davismcphee:backport/8.15/pr-193791
Sep 25, 2024
Merged

[8.15] [Unified Data Table] Prevent undefined errors when row accessed via rows[rowIndex] (#193791)#193921
davismcphee merged 1 commit intoelastic:8.15from
davismcphee:backport/8.15/pr-193791

Conversation

@davismcphee
Copy link
Copy Markdown
Contributor

Backport

This will backport the following commits from main to 8.15:

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)

# Conflicts:
#	packages/kbn-unified-data-table/__mocks__/table_context.ts
#	packages/kbn-unified-data-table/src/components/custom_control_columns/additional_row_control/row_control_column.test.tsx
#	packages/kbn-unified-data-table/src/components/custom_control_columns/additional_row_control/row_control_column.tsx
#	packages/kbn-unified-data-table/src/components/custom_control_columns/additional_row_control/row_menu_control_column.test.tsx
#	packages/kbn-unified-data-table/src/components/custom_control_columns/additional_row_control/row_menu_control_column.tsx
#	packages/kbn-unified-data-table/src/components/custom_control_columns/color_indicator/color_indicator_control_column.test.tsx
#	packages/kbn-unified-data-table/src/components/data_table.tsx
#	packages/kbn-unified-data-table/src/components/data_table_columns.tsx
#	packages/kbn-unified-data-table/src/components/data_table_copy_rows_as_json.tsx
#	packages/kbn-unified-data-table/src/components/data_table_copy_rows_as_text.tsx
#	packages/kbn-unified-data-table/src/components/data_table_document_selection.test.tsx
#	packages/kbn-unified-data-table/src/components/data_table_document_selection.tsx
#	packages/kbn-unified-data-table/src/components/data_table_expand_button.tsx
#	packages/kbn-unified-data-table/src/hooks/use_control_column.ts
#	packages/kbn-unified-data-table/src/utils/copy_value_to_clipboard.test.tsx
@davismcphee davismcphee added the backport This PR is a backport of another PR label Sep 24, 2024
@davismcphee davismcphee enabled auto-merge (squash) September 24, 2024 20:34
@davismcphee davismcphee added Feature:Discover Discover Application release_note:fix Team:DataDiscovery Discover, search (data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. t// Feature:UnifiedDataTable labels Sep 24, 2024
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/kibana-data-discovery (Team:DataDiscovery)

@kibana-ci
Copy link
Copy Markdown

💚 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 453.2KB 453.3KB +120.0B
discover 810.3KB 810.4KB +120.0B
esqlDataGrid 114.9KB 115.0KB +120.0B
securitySolution 17.2MB 17.2MB +600.0B
slo 870.5KB 870.6KB +120.0B
total +1.1KB

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

Copy link
Copy Markdown
Member

@kertal kertal left a comment

Choose a reason for hiding this comment

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

LGTM, I've tested this PR on a a-la-carte

  • first without this fix (could reproduce the race condition, but not reliable, but this is the nature of race conditions 🏃)
  • then I applied this fix, and I could no longer reproduce it, so it works as expected, 🙏 for taking care of this so quickly

@davismcphee davismcphee merged commit 265a614 into elastic:8.15 Sep 25, 2024
@davismcphee davismcphee deleted the backport/8.15/pr-193791 branch September 25, 2024 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport This PR is a backport of another PR Feature:Discover Discover Application Feature:UnifiedDataTable release_note:fix Team:DataDiscovery Discover, search (data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. t//

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants