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

[EuiProvider/Security Solution] Remove usage of deprecated React rendering utilities #181099

Merged

Conversation

tsullivan
Copy link
Member

@tsullivan tsullivan commented Apr 18, 2024

Summary

Partially addresses https://github.com/elastic/kibana-team/issues/805

These changes come up from searching in the code and finding where certain kinds of deprecated AppEx-SharedUX modules are imported. Reviewers: Please interact with critical paths through the UI components touched in this PR, ESPECIALLY in terms of testing dark mode and i18n.

This focuses on code within Security Solution.

image

Note: this also makes inclusion of i18n and analytics dependencies consistent. Analytics is an optional dependency for the SharedUX modules, which wrap KibanaErrorBoundaryProvider and is designed to capture telemetry about errors that are caught in the error boundary.

Checklist

Delete any items that are not applicable to this PR.

@tsullivan tsullivan force-pushed the sharedux/cleanup-tomountpoint-deprecations-viii branch 2 times, most recently from 9b0343c to 7bdbf29 Compare April 18, 2024 23:37
@tsullivan
Copy link
Member Author

/ci

@tsullivan tsullivan force-pushed the sharedux/cleanup-tomountpoint-deprecations-viii branch from 7bdbf29 to 7e947e9 Compare April 22, 2024 18:13
@tsullivan
Copy link
Member Author

/ci

@tsullivan tsullivan marked this pull request as ready for review April 22, 2024 22:04
@tsullivan tsullivan requested review from a team as code owners April 22, 2024 22:04
@tsullivan tsullivan added the release_note:skip Skip the PR/issue when compiling release notes label Apr 22, 2024
Copy link
Contributor

@patrykkopycinski patrykkopycinski left a comment

Choose a reason for hiding this comment

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

Thank you! 🙇

Copy link
Member

@machadoum machadoum left a comment

Choose a reason for hiding this comment

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

Entity Analytics code LGTM.

I tested EA pages and couldn't find any problem.

Copy link
Contributor

@vitaliidm vitaliidm left a comment

Choose a reason for hiding this comment

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

Detection area LGTM
I did quick check with light and dark theme and did not notice anything off

Copy link
Contributor

@xcrzx xcrzx 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 both light and dark themes, LGTM!

@tsullivan tsullivan added technical debt Improvement of the software architecture and operational architecture Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. labels Apr 24, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

Copy link
Contributor

@gergoabraham gergoabraham left a comment

Choose a reason for hiding this comment

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

@elastic/security-defend-workflows related changes look good! played around on our pages using dark mode, no issues found - thank you for the changes! 🙌

@tsullivan
Copy link
Member Author

/ci

@tsullivan tsullivan enabled auto-merge (squash) April 26, 2024 21:54
@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
securitySolution 13.7MB 13.7MB -1.9KB
Unknown metric groups

References to deprecated APIs

id before after diff
securitySolution 537 521 -16

History

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

@tsullivan tsullivan merged commit 4983271 into elastic:main Apr 27, 2024
35 checks passed
@kibanamachine kibanamachine added v8.15.0 backport:skip This commit does not require backporting labels Apr 27, 2024
@tsullivan tsullivan deleted the sharedux/cleanup-tomountpoint-deprecations-viii branch April 27, 2024 01:32
tsullivan added a commit that referenced this pull request May 7, 2024
…eact, Part II (#182061)

## Summary

Partially addresses elastic/kibana-team#805

These changes come up from searching in the code and finding where
certain kinds of deprecated AppEx-SharedUX modules are imported.
**Reviewers: Please interact with critical paths through the UI
components touched in this PR, ESPECIALLY in terms of testing dark mode
and i18n.**

This is the **2nd** PR to focus on code within **Security Solution**,
following #181099.

<img width="1196" alt="image"
src="https://github.com/elastic/kibana/assets/908371/7f8d3707-94f0-4746-8dd5-dd858ce027f9">

Note: this also makes inclusion of `i18n` and `analytics` dependencies
consistent. Analytics is an optional dependency for the SharedUX
modules, which wrap `KibanaErrorBoundaryProvider` and is designed to
capture telemetry about errors that are caught in the error boundary.

### Checklist

Delete any items that are not applicable to this PR.

- [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
- [ ] 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)
maximpn added a commit that referenced this pull request Jul 15, 2024
**Resolves:** #177734

## Summary

This PR fixes a non-responsive rule details page under non default space.

## Details

**[Security Solution] Rule details page is not responsive and leads to page crash for rule in non-default spaces [#177734](#177734 resurfaced back. Investigation has show that **[Security Solution] Remove usage of deprecated React rendering utilities [#181099](#181099 is the cause.

The problem is quite subtle to comprehend it just by looking at the code. In fact it boils down to an unstable `useAsync()` hook dependency. Every re-render `useAsync()` resolves a promise causing an additional re-render to show updated results and the cycle repeats. Such hook is used in `x-pack/plugins/security_solution/public/common/components/visualization_actions/actions.tsx`

```ts
  const panels = useAsync(
    () =>
      buildContextMenuForActions({
        actions: contextMenuActions.map((action) => ({
          action,
          context: {},
          trigger: VISUALIZATION_CONTEXT_MENU_TRIGGER,
        })),
      }),
    [contextMenuActions]
  );
```

where `contextMenuActions` is an unstable dependency. This is the case due to refactoring to `useSaveToLibrary()` hook by **[Security Solution] Remove usage of deprecated React rendering utilities [#181099](#181099 which started retuning a new object every render. The dependency chain is  `contextMenuActions` -> `useActions()` -> `useSaveToLibrary()`.

The actual fix is to replace

```ts
const { lens, ...startServices } = useKibana().services;
```

with

```ts
const startServices = useKibana().services;
```

Since `startServices` is used as a hook dependency it must be stable. A rest property in object destruction expression is always a new object and can't be used as a dependency as is. Using stable `useKibana().services` fixes the problem.
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jul 15, 2024
)

**Resolves:** elastic#177734

## Summary

This PR fixes a non-responsive rule details page under non default space.

## Details

**[Security Solution] Rule details page is not responsive and leads to page crash for rule in non-default spaces [elastic#177734](elastic#177734 resurfaced back. Investigation has show that **[Security Solution] Remove usage of deprecated React rendering utilities [elastic#181099](elastic#181099 is the cause.

The problem is quite subtle to comprehend it just by looking at the code. In fact it boils down to an unstable `useAsync()` hook dependency. Every re-render `useAsync()` resolves a promise causing an additional re-render to show updated results and the cycle repeats. Such hook is used in `x-pack/plugins/security_solution/public/common/components/visualization_actions/actions.tsx`

```ts
  const panels = useAsync(
    () =>
      buildContextMenuForActions({
        actions: contextMenuActions.map((action) => ({
          action,
          context: {},
          trigger: VISUALIZATION_CONTEXT_MENU_TRIGGER,
        })),
      }),
    [contextMenuActions]
  );
```

where `contextMenuActions` is an unstable dependency. This is the case due to refactoring to `useSaveToLibrary()` hook by **[Security Solution] Remove usage of deprecated React rendering utilities [elastic#181099](elastic#181099 which started retuning a new object every render. The dependency chain is  `contextMenuActions` -> `useActions()` -> `useSaveToLibrary()`.

The actual fix is to replace

```ts
const { lens, ...startServices } = useKibana().services;
```

with

```ts
const startServices = useKibana().services;
```

Since `startServices` is used as a hook dependency it must be stable. A rest property in object destruction expression is always a new object and can't be used as a dependency as is. Using stable `useKibana().services` fixes the problem.

(cherry picked from commit 8a539a8)
kibanamachine added a commit that referenced this pull request Jul 15, 2024
) (#188305)

# Backport

This will backport the following commits from `main` to `8.15`:
- [[Security Solution] Fix non-responsive rule details page
(#187953)](#187953)

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

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

<!--BACKPORT [{"author":{"name":"Maxim
Palenov","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-07-15T11:37:26Z","message":"[Security
Solution] Fix non-responsive rule details page
(#187953)\n\n**Resolves:**
https://github.com/elastic/kibana/issues/177734\r\n\r\n##
Summary\r\n\r\nThis PR fixes a non-responsive rule details page under
non default space.\r\n\r\n## Details\r\n\r\n**[Security Solution] Rule
details page is not responsive and leads to page crash for rule in
non-default spaces
[#177734](#177734 resurfaced
back. Investigation has show that **[Security Solution] Remove usage of
deprecated React rendering utilities
[#181099](#181099 is the
cause.\r\n\r\nThe problem is quite subtle to comprehend it just by
looking at the code. In fact it boils down to an unstable `useAsync()`
hook dependency. Every re-render `useAsync()` resolves a promise causing
an additional re-render to show updated results and the cycle repeats.
Such hook is used in
`x-pack/plugins/security_solution/public/common/components/visualization_actions/actions.tsx`\r\n\r\n```ts\r\n
const panels = useAsync(\r\n () =>\r\n buildContextMenuForActions({\r\n
actions: contextMenuActions.map((action) => ({\r\n action,\r\n context:
{},\r\n trigger: VISUALIZATION_CONTEXT_MENU_TRIGGER,\r\n })),\r\n
}),\r\n [contextMenuActions]\r\n );\r\n```\r\n\r\nwhere
`contextMenuActions` is an unstable dependency. This is the case due to
refactoring to `useSaveToLibrary()` hook by **[Security Solution] Remove
usage of deprecated React rendering utilities
[#181099](#181099 which started
retuning a new object every render. The dependency chain is
`contextMenuActions` -> `useActions()` ->
`useSaveToLibrary()`.\r\n\r\nThe actual fix is to
replace\r\n\r\n```ts\r\nconst { lens, ...startServices } =
useKibana().services;\r\n```\r\n\r\nwith\r\n\r\n```ts\r\nconst
startServices = useKibana().services;\r\n```\r\n\r\nSince
`startServices` is used as a hook dependency it must be stable. A rest
property in object destruction expression is always a new object and
can't be used as a dependency as is. Using stable `useKibana().services`
fixes the
problem.","sha":"8a539a8a4ce483d2e5d3aa484d8ec78887f338b8","branchLabelMapping":{"^v8.16.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","impact:critical","Team:Detections
and Resp","Team: SecuritySolution","Team:Detection Rule
Management","Feature:Rule
Details","v8.15.0","v8.16.0"],"title":"[Security Solution] Fix
non-responsive rule details
page","number":187953,"url":"https://github.com/elastic/kibana/pull/187953","mergeCommit":{"message":"[Security
Solution] Fix non-responsive rule details page
(#187953)\n\n**Resolves:**
https://github.com/elastic/kibana/issues/177734\r\n\r\n##
Summary\r\n\r\nThis PR fixes a non-responsive rule details page under
non default space.\r\n\r\n## Details\r\n\r\n**[Security Solution] Rule
details page is not responsive and leads to page crash for rule in
non-default spaces
[#177734](#177734 resurfaced
back. Investigation has show that **[Security Solution] Remove usage of
deprecated React rendering utilities
[#181099](#181099 is the
cause.\r\n\r\nThe problem is quite subtle to comprehend it just by
looking at the code. In fact it boils down to an unstable `useAsync()`
hook dependency. Every re-render `useAsync()` resolves a promise causing
an additional re-render to show updated results and the cycle repeats.
Such hook is used in
`x-pack/plugins/security_solution/public/common/components/visualization_actions/actions.tsx`\r\n\r\n```ts\r\n
const panels = useAsync(\r\n () =>\r\n buildContextMenuForActions({\r\n
actions: contextMenuActions.map((action) => ({\r\n action,\r\n context:
{},\r\n trigger: VISUALIZATION_CONTEXT_MENU_TRIGGER,\r\n })),\r\n
}),\r\n [contextMenuActions]\r\n );\r\n```\r\n\r\nwhere
`contextMenuActions` is an unstable dependency. This is the case due to
refactoring to `useSaveToLibrary()` hook by **[Security Solution] Remove
usage of deprecated React rendering utilities
[#181099](#181099 which started
retuning a new object every render. The dependency chain is
`contextMenuActions` -> `useActions()` ->
`useSaveToLibrary()`.\r\n\r\nThe actual fix is to
replace\r\n\r\n```ts\r\nconst { lens, ...startServices } =
useKibana().services;\r\n```\r\n\r\nwith\r\n\r\n```ts\r\nconst
startServices = useKibana().services;\r\n```\r\n\r\nSince
`startServices` is used as a hook dependency it must be stable. A rest
property in object destruction expression is always a new object and
can't be used as a dependency as is. Using stable `useKibana().services`
fixes the
problem.","sha":"8a539a8a4ce483d2e5d3aa484d8ec78887f338b8"}},"sourceBranch":"main","suggestedTargetBranches":["8.15"],"targetPullRequestStates":[{"branch":"8.15","label":"v8.15.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/187953","number":187953,"mergeCommit":{"message":"[Security
Solution] Fix non-responsive rule details page
(#187953)\n\n**Resolves:**
https://github.com/elastic/kibana/issues/177734\r\n\r\n##
Summary\r\n\r\nThis PR fixes a non-responsive rule details page under
non default space.\r\n\r\n## Details\r\n\r\n**[Security Solution] Rule
details page is not responsive and leads to page crash for rule in
non-default spaces
[#177734](#177734 resurfaced
back. Investigation has show that **[Security Solution] Remove usage of
deprecated React rendering utilities
[#181099](#181099 is the
cause.\r\n\r\nThe problem is quite subtle to comprehend it just by
looking at the code. In fact it boils down to an unstable `useAsync()`
hook dependency. Every re-render `useAsync()` resolves a promise causing
an additional re-render to show updated results and the cycle repeats.
Such hook is used in
`x-pack/plugins/security_solution/public/common/components/visualization_actions/actions.tsx`\r\n\r\n```ts\r\n
const panels = useAsync(\r\n () =>\r\n buildContextMenuForActions({\r\n
actions: contextMenuActions.map((action) => ({\r\n action,\r\n context:
{},\r\n trigger: VISUALIZATION_CONTEXT_MENU_TRIGGER,\r\n })),\r\n
}),\r\n [contextMenuActions]\r\n );\r\n```\r\n\r\nwhere
`contextMenuActions` is an unstable dependency. This is the case due to
refactoring to `useSaveToLibrary()` hook by **[Security Solution] Remove
usage of deprecated React rendering utilities
[#181099](#181099 which started
retuning a new object every render. The dependency chain is
`contextMenuActions` -> `useActions()` ->
`useSaveToLibrary()`.\r\n\r\nThe actual fix is to
replace\r\n\r\n```ts\r\nconst { lens, ...startServices } =
useKibana().services;\r\n```\r\n\r\nwith\r\n\r\n```ts\r\nconst
startServices = useKibana().services;\r\n```\r\n\r\nSince
`startServices` is used as a hook dependency it must be stable. A rest
property in object destruction expression is always a new object and
can't be used as a dependency as is. Using stable `useKibana().services`
fixes the
problem.","sha":"8a539a8a4ce483d2e5d3aa484d8ec78887f338b8"}}]}]
BACKPORT-->

Co-authored-by: Maxim Palenov <[email protected]>
@tsullivan tsullivan changed the title [Security Solution] Remove usage of deprecated React rendering utilities [EuiProvider/Security Solution] Remove usage of deprecated React rendering utilities Jul 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. technical debt Improvement of the software architecture and operational architecture v8.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants