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

[Security Solution] Fix non-responsive rule details page #187953

Merged
merged 2 commits into from
Jul 15, 2024

Conversation

maximpn
Copy link
Contributor

@maximpn maximpn commented Jul 10, 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 resurfaced back. Investigation has show that [Security Solution] Remove usage of deprecated React rendering utilities #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

  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 which started retuning a new object every render. The dependency chain is contextMenuActions -> useActions() -> useSaveToLibrary().

The actual fix is to replace

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

with

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.

@maximpn maximpn added bug Fixes for quality problems that affect the customer experience release_note:skip Skip the PR/issue when compiling release notes impact:critical This issue should be addressed immediately due to a critical level of impact on the product. Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Team:Detection Rule Management Security Detection Rule Management Team Feature:Rule Details Security Solution Detection Rule Details page v8.15.0 labels Jul 10, 2024
@maximpn maximpn self-assigned this Jul 10, 2024
@maximpn maximpn requested a review from xcrzx July 10, 2024 10:59
@maximpn maximpn marked this pull request as ready for review July 10, 2024 11:00
@maximpn maximpn requested a review from a team as a code owner July 10, 2024 11:00
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-detections-response (Team:Detections and Resp)

@elasticmachine
Copy link
Contributor

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

@elasticmachine
Copy link
Contributor

Pinging @elastic/security-detection-rule-management (Team:Detection Rule Management)

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.

Is that possible to add a Cypress test for non-default space to catch it early?
It happened second time in few months and was discovered by accident.
Having dedicated test that ensures rule details page is loading would be beneficial

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, the rule details page loads without any issues in a non-default space. Thanks for the fix, @maximpn 👍

@maximpn maximpn force-pushed the fix-non-responsive-rule-details-page branch from c85cd51 to f54c764 Compare July 15, 2024 08:53
@maximpn maximpn requested review from a team as code owners July 15, 2024 08:53
@maximpn maximpn requested a review from nikitaindik July 15, 2024 08:53
@maximpn maximpn force-pushed the fix-non-responsive-rule-details-page branch from f54c764 to 3196198 Compare July 15, 2024 10:11
@maximpn maximpn merged commit 8a539a8 into elastic:main Jul 15, 2024
39 checks passed
@maximpn maximpn deleted the fix-non-responsive-rule-details-page branch July 15, 2024 11:37
@elastic elastic deleted a comment from elasticmachine Jul 15, 2024
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
Copy link
Contributor

💚 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

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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes for quality problems that affect the customer experience Feature:Rule Details Security Solution Detection Rule Details page impact:critical This issue should be addressed immediately due to a critical level of impact on the product. release_note:skip Skip the PR/issue when compiling release notes Team:Detection Rule Management Security Detection Rule Management Team Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v8.15.0 v8.16.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants