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

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

Merged

Conversation

davismcphee
Copy link
Contributor

@davismcphee davismcphee commented Sep 23, 2024

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

For maintainers

…can result in undefined reference errors that can't be caught by TS
@davismcphee davismcphee added Feature:Discover Discover Application release_note:fix Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) backport:prev-major Backport to (8.x, 8.17, 8.16) the previous major branch and other branches in development Feature:UnifiedDataTable labels Sep 23, 2024
@davismcphee davismcphee self-assigned this Sep 23, 2024
@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #82 / management index pattern not found redirects to the main view if data view is missing
  • [job] [logs] Jest Integration Tests #4 / when rolling back to an older version kibana should detect that a later version alias exists, and abort

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.9KB 813.2KB +327.0B
esqlDataGrid 153.0KB 153.3KB +327.0B
securitySolution 20.4MB 20.4MB +1.6KB
slo 854.1KB 854.4KB +322.0B
total +2.8KB

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

cc @davismcphee

@davismcphee davismcphee changed the title [Unified Data Table] Prevent undefined errors when row accessed view rows[rowIndex] [Unified Data Table] Prevent undefined errors when row accessed via rows[rowIndex] Sep 24, 2024
@davismcphee davismcphee marked this pull request as ready for review September 24, 2024 01:08
@davismcphee davismcphee requested review from a team as code owners September 24, 2024 01:08
@elasticmachine
Copy link
Contributor

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

Copy link
Contributor

@jughosta jughosta left a comment

Choose a reason for hiding this comment

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

Nice refactoring, thanks! LGTM 👍

const { getCountOfFilteredSelectedDocs, deselectSomeDocs, selectMoreDocs } = selectedDocsState;

const docIdsFromCurrentPage = useMemo(() => {
return getDocIdsForCurrentPage(rows, pageIndex, pageSize);
}, [rows, pageIndex, pageSize]);
}, [pageIndex, pageSize]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this change intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes because getSelectAllButton is now a function that accepts rows as a param and returns a component, so rows in no longer a part of the React lifecycle and will only change whenever getSelectAllButton is called.

@davismcphee davismcphee merged commit 6ff0791 into elastic:main Sep 24, 2024
30 checks passed
@davismcphee davismcphee deleted the fix-unified-data-table-undefined-row branch September 24, 2024 18:36
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Sep 24, 2024
… `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)
@kibanamachine
Copy link
Contributor

💔 Some backports could not be created

Status Branch Result
8.15 Backport failed because of merge conflicts
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Manual backport

To create the backport manually run:

node scripts/backport --pr 193791

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Sep 24, 2024
…row accessed via `rows[rowIndex]` (#193791) (#193908)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Unified Data Table] Prevent `undefined` errors when row
accessed via `rows[rowIndex]`
(#193791)](#193791)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Davis
McPhee","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-09-24T18:36:11Z","message":"[Unified
Data Table] Prevent `undefined` errors when row accessed via
`rows[rowIndex]` (#193791)\n\n## Summary\r\n\r\nThis PR fixes an issue
present in 8.15, but which no longer exists after\r\nlater refactoring,
where saved search panels (possibly only ES|QL\r\npanels? It was hard to
nail down since involved a race condition) could\r\nfail in dashboards
when adding Unified Search filters that reduce the\r\nnumber of results
in the grid.\r\n\r\nI'm still not 100% sure what the source of the issue
was since it\r\ninvolved a race condition (didn't fail consistently for
me locally) and\r\ninternal EUI data grid code, but I have a hunch. The
`undefined` errors\r\noccurred when trying to access a row by index from
`DataTableContext` in\r\ncertain cell renderers during the first render
after search results had\r\nchanged. I believe what was happening was
the change to\r\n`DataTableContext` triggered a re-render of the cells
before EUI data\r\ngrid internally updated its state, resulting in
attempts to access rows\r\nfrom within the cell renderers that no longer
existed in the updated\r\n`DataTableContext`, and causing `undefined`
reference errors.\r\n\r\nI'm making these changes in `main` instead of
`8.15` directly because\r\nthe updated approach is generally a safer way
to retrieve rows and\r\nprevent similar issues in the future. Previously
we added `rows` to\r\n`DataTableContext` and retrieved a single row by
index using bracket\r\nnotation, which can potentially return
`undefined`, but TypeScript does\r\nnot protect against it for us.
Instead I've updated `DataTableContext`\r\nwith a `getRowByIndex` method
that correctly returns `DataTableRecord |\r\nundefined` and forces
consumers to explicitly handle the `undefined`\r\nscenario.\r\n\r\nThe
PR will require some manual backporting to 8.15 since some
things\r\nhave changed since then, but it shouldn't be
difficult.\r\n\r\n### Checklist\r\n\r\n- [ ] Any text added follows
[EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [x] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[ ] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n###
For maintainers\r\n\r\n- [ ] This was checked for breaking API changes
and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"6ff07918b0490fa7d66202376073a337da55c73e","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Discover","release_note:fix","v9.0.0","Team:DataDiscovery","backport:prev-minor","backport:prev-major","Feature:UnifiedDataTable"],"title":"[Unified
Data Table] Prevent `undefined` errors when row accessed via
`rows[rowIndex]`","number":193791,"url":"https://github.com/elastic/kibana/pull/193791","mergeCommit":{"message":"[Unified
Data Table] Prevent `undefined` errors when row accessed via
`rows[rowIndex]` (#193791)\n\n## Summary\r\n\r\nThis PR fixes an issue
present in 8.15, but which no longer exists after\r\nlater refactoring,
where saved search panels (possibly only ES|QL\r\npanels? It was hard to
nail down since involved a race condition) could\r\nfail in dashboards
when adding Unified Search filters that reduce the\r\nnumber of results
in the grid.\r\n\r\nI'm still not 100% sure what the source of the issue
was since it\r\ninvolved a race condition (didn't fail consistently for
me locally) and\r\ninternal EUI data grid code, but I have a hunch. The
`undefined` errors\r\noccurred when trying to access a row by index from
`DataTableContext` in\r\ncertain cell renderers during the first render
after search results had\r\nchanged. I believe what was happening was
the change to\r\n`DataTableContext` triggered a re-render of the cells
before EUI data\r\ngrid internally updated its state, resulting in
attempts to access rows\r\nfrom within the cell renderers that no longer
existed in the updated\r\n`DataTableContext`, and causing `undefined`
reference errors.\r\n\r\nI'm making these changes in `main` instead of
`8.15` directly because\r\nthe updated approach is generally a safer way
to retrieve rows and\r\nprevent similar issues in the future. Previously
we added `rows` to\r\n`DataTableContext` and retrieved a single row by
index using bracket\r\nnotation, which can potentially return
`undefined`, but TypeScript does\r\nnot protect against it for us.
Instead I've updated `DataTableContext`\r\nwith a `getRowByIndex` method
that correctly returns `DataTableRecord |\r\nundefined` and forces
consumers to explicitly handle the `undefined`\r\nscenario.\r\n\r\nThe
PR will require some manual backporting to 8.15 since some
things\r\nhave changed since then, but it shouldn't be
difficult.\r\n\r\n### Checklist\r\n\r\n- [ ] Any text added follows
[EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [x] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[ ] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n###
For maintainers\r\n\r\n- [ ] This was checked for breaking API changes
and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"6ff07918b0490fa7d66202376073a337da55c73e"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/193791","number":193791,"mergeCommit":{"message":"[Unified
Data Table] Prevent `undefined` errors when row accessed via
`rows[rowIndex]` (#193791)\n\n## Summary\r\n\r\nThis PR fixes an issue
present in 8.15, but which no longer exists after\r\nlater refactoring,
where saved search panels (possibly only ES|QL\r\npanels? It was hard to
nail down since involved a race condition) could\r\nfail in dashboards
when adding Unified Search filters that reduce the\r\nnumber of results
in the grid.\r\n\r\nI'm still not 100% sure what the source of the issue
was since it\r\ninvolved a race condition (didn't fail consistently for
me locally) and\r\ninternal EUI data grid code, but I have a hunch. The
`undefined` errors\r\noccurred when trying to access a row by index from
`DataTableContext` in\r\ncertain cell renderers during the first render
after search results had\r\nchanged. I believe what was happening was
the change to\r\n`DataTableContext` triggered a re-render of the cells
before EUI data\r\ngrid internally updated its state, resulting in
attempts to access rows\r\nfrom within the cell renderers that no longer
existed in the updated\r\n`DataTableContext`, and causing `undefined`
reference errors.\r\n\r\nI'm making these changes in `main` instead of
`8.15` directly because\r\nthe updated approach is generally a safer way
to retrieve rows and\r\nprevent similar issues in the future. Previously
we added `rows` to\r\n`DataTableContext` and retrieved a single row by
index using bracket\r\nnotation, which can potentially return
`undefined`, but TypeScript does\r\nnot protect against it for us.
Instead I've updated `DataTableContext`\r\nwith a `getRowByIndex` method
that correctly returns `DataTableRecord |\r\nundefined` and forces
consumers to explicitly handle the `undefined`\r\nscenario.\r\n\r\nThe
PR will require some manual backporting to 8.15 since some
things\r\nhave changed since then, but it shouldn't be
difficult.\r\n\r\n### Checklist\r\n\r\n- [ ] Any text added follows
[EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [x] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[ ] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n###
For maintainers\r\n\r\n- [ ] This was checked for breaking API changes
and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"6ff07918b0490fa7d66202376073a337da55c73e"}}]}]
BACKPORT-->

Co-authored-by: Davis McPhee <[email protected]>
@davismcphee
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
8.15

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

davismcphee added a commit to davismcphee/kibana that referenced this pull request Sep 24, 2024
… `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 added a commit that referenced this pull request Sep 25, 2024
…sed via `rows[rowIndex]` (#193791) (#193921)

# Backport

This will backport the following commits from `main` to `8.15`:
- [[Unified Data Table] Prevent `undefined` errors when row accessed via
`rows[rowIndex]`
(#193791)](#193791)

<!--- Backport version: 8.9.8 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Davis
McPhee","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-09-24T18:36:11Z","message":"[Unified
Data Table] Prevent `undefined` errors when row accessed via
`rows[rowIndex]` (#193791)\n\n## Summary\r\n\r\nThis PR fixes an issue
present in 8.15, but which no longer exists after\r\nlater refactoring,
where saved search panels (possibly only ES|QL\r\npanels? It was hard to
nail down since involved a race condition) could\r\nfail in dashboards
when adding Unified Search filters that reduce the\r\nnumber of results
in the grid.\r\n\r\nI'm still not 100% sure what the source of the issue
was since it\r\ninvolved a race condition (didn't fail consistently for
me locally) and\r\ninternal EUI data grid code, but I have a hunch. The
`undefined` errors\r\noccurred when trying to access a row by index from
`DataTableContext` in\r\ncertain cell renderers during the first render
after search results had\r\nchanged. I believe what was happening was
the change to\r\n`DataTableContext` triggered a re-render of the cells
before EUI data\r\ngrid internally updated its state, resulting in
attempts to access rows\r\nfrom within the cell renderers that no longer
existed in the updated\r\n`DataTableContext`, and causing `undefined`
reference errors.\r\n\r\nI'm making these changes in `main` instead of
`8.15` directly because\r\nthe updated approach is generally a safer way
to retrieve rows and\r\nprevent similar issues in the future. Previously
we added `rows` to\r\n`DataTableContext` and retrieved a single row by
index using bracket\r\nnotation, which can potentially return
`undefined`, but TypeScript does\r\nnot protect against it for us.
Instead I've updated `DataTableContext`\r\nwith a `getRowByIndex` method
that correctly returns `DataTableRecord |\r\nundefined` and forces
consumers to explicitly handle the `undefined`\r\nscenario.\r\n\r\nThe
PR will require some manual backporting to 8.15 since some
things\r\nhave changed since then, but it shouldn't be
difficult.\r\n\r\n### Checklist\r\n\r\n- [ ] Any text added follows
[EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [x] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[ ] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n###
For maintainers\r\n\r\n- [ ] This was checked for breaking API changes
and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"6ff07918b0490fa7d66202376073a337da55c73e","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Discover","release_note:fix","v9.0.0","Team:DataDiscovery","backport:prev-minor","backport:prev-major","Feature:UnifiedDataTable"],"number":193791,"url":"https://github.com/elastic/kibana/pull/193791","mergeCommit":{"message":"[Unified
Data Table] Prevent `undefined` errors when row accessed via
`rows[rowIndex]` (#193791)\n\n## Summary\r\n\r\nThis PR fixes an issue
present in 8.15, but which no longer exists after\r\nlater refactoring,
where saved search panels (possibly only ES|QL\r\npanels? It was hard to
nail down since involved a race condition) could\r\nfail in dashboards
when adding Unified Search filters that reduce the\r\nnumber of results
in the grid.\r\n\r\nI'm still not 100% sure what the source of the issue
was since it\r\ninvolved a race condition (didn't fail consistently for
me locally) and\r\ninternal EUI data grid code, but I have a hunch. The
`undefined` errors\r\noccurred when trying to access a row by index from
`DataTableContext` in\r\ncertain cell renderers during the first render
after search results had\r\nchanged. I believe what was happening was
the change to\r\n`DataTableContext` triggered a re-render of the cells
before EUI data\r\ngrid internally updated its state, resulting in
attempts to access rows\r\nfrom within the cell renderers that no longer
existed in the updated\r\n`DataTableContext`, and causing `undefined`
reference errors.\r\n\r\nI'm making these changes in `main` instead of
`8.15` directly because\r\nthe updated approach is generally a safer way
to retrieve rows and\r\nprevent similar issues in the future. Previously
we added `rows` to\r\n`DataTableContext` and retrieved a single row by
index using bracket\r\nnotation, which can potentially return
`undefined`, but TypeScript does\r\nnot protect against it for us.
Instead I've updated `DataTableContext`\r\nwith a `getRowByIndex` method
that correctly returns `DataTableRecord |\r\nundefined` and forces
consumers to explicitly handle the `undefined`\r\nscenario.\r\n\r\nThe
PR will require some manual backporting to 8.15 since some
things\r\nhave changed since then, but it shouldn't be
difficult.\r\n\r\n### Checklist\r\n\r\n- [ ] Any text added follows
[EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [x] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[ ] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n###
For maintainers\r\n\r\n- [ ] This was checked for breaking API changes
and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"6ff07918b0490fa7d66202376073a337da55c73e"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/193791","number":193791,"mergeCommit":{"message":"[Unified
Data Table] Prevent `undefined` errors when row accessed via
`rows[rowIndex]` (#193791)\n\n## Summary\r\n\r\nThis PR fixes an issue
present in 8.15, but which no longer exists after\r\nlater refactoring,
where saved search panels (possibly only ES|QL\r\npanels? It was hard to
nail down since involved a race condition) could\r\nfail in dashboards
when adding Unified Search filters that reduce the\r\nnumber of results
in the grid.\r\n\r\nI'm still not 100% sure what the source of the issue
was since it\r\ninvolved a race condition (didn't fail consistently for
me locally) and\r\ninternal EUI data grid code, but I have a hunch. The
`undefined` errors\r\noccurred when trying to access a row by index from
`DataTableContext` in\r\ncertain cell renderers during the first render
after search results had\r\nchanged. I believe what was happening was
the change to\r\n`DataTableContext` triggered a re-render of the cells
before EUI data\r\ngrid internally updated its state, resulting in
attempts to access rows\r\nfrom within the cell renderers that no longer
existed in the updated\r\n`DataTableContext`, and causing `undefined`
reference errors.\r\n\r\nI'm making these changes in `main` instead of
`8.15` directly because\r\nthe updated approach is generally a safer way
to retrieve rows and\r\nprevent similar issues in the future. Previously
we added `rows` to\r\n`DataTableContext` and retrieved a single row by
index using bracket\r\nnotation, which can potentially return
`undefined`, but TypeScript does\r\nnot protect against it for us.
Instead I've updated `DataTableContext`\r\nwith a `getRowByIndex` method
that correctly returns `DataTableRecord |\r\nundefined` and forces
consumers to explicitly handle the `undefined`\r\nscenario.\r\n\r\nThe
PR will require some manual backporting to 8.15 since some
things\r\nhave changed since then, but it shouldn't be
difficult.\r\n\r\n### Checklist\r\n\r\n- [ ] Any text added follows
[EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [x] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[ ] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n###
For maintainers\r\n\r\n- [ ] This was checked for breaking API changes
and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"6ff07918b0490fa7d66202376073a337da55c73e"}},{"url":"https://github.com/elastic/kibana/pull/193908","number":193908,"branch":"8.x","state":"OPEN"}]}]
BACKPORT-->
delanni added a commit that referenced this pull request Sep 25, 2024
delanni added a commit that referenced this pull request Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-major Backport to (8.x, 8.17, 8.16) the previous major branch and other branches in development backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) Feature:Discover Discover Application Feature:UnifiedDataTable release_note:fix Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. v8.15.2 v8.16.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants