From 21b087a15a308f2df374aa975aad715dbf2498dc Mon Sep 17 00:00:00 2001 From: Philippe Oberti Date: Mon, 23 Dec 2024 09:55:30 -0600 Subject: [PATCH] [Security Solution] - fixing infinite look on host flyout panel due to lack of memoization (#204999) ## Summary This PR fixes [an issue](https://github.com/elastic/security-team/issues/11424) raised recently where opening a preview panel for a host of user on top of a flyout already showing a host or user was getting the UI stuck into an infinite loop. While we found a few ways to fix the issue - primarily adding memoization to the UI components within the HostPanel and UserPanel, the approach in this PR fixes the issue at a more root level. Infinite loop behavior https://github.com/user-attachments/assets/92cb60ad-7801-43ec-a247-8943e091b6a8 Issue fixed https://github.com/user-attachments/assets/30b30b42-f32e-4c02-9407-9d0f671d7216 This fix should also potentially bring some performance improvement to all the components that are using the hook (we have a few). (cherry picked from commit 96264d29237f0b7cfc8c651393f12d248f0d84e0) --- .../alerts_by_status/use_alerts_by_status.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/x-pack/solutions/security/plugins/security_solution/public/overview/components/detection_response/alerts_by_status/use_alerts_by_status.ts b/x-pack/solutions/security/plugins/security_solution/public/overview/components/detection_response/alerts_by_status/use_alerts_by_status.ts index e80f3ec0a0caf..9af905cab8580 100644 --- a/x-pack/solutions/security/plugins/security_solution/public/overview/components/detection_response/alerts_by_status/use_alerts_by_status.ts +++ b/x-pack/solutions/security/plugins/security_solution/public/overview/components/detection_response/alerts_by_status/use_alerts_by_status.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { useCallback, useEffect, useState } from 'react'; +import { useCallback, useEffect, useMemo, useState } from 'react'; import type { Severity } from '@kbn/securitysolution-io-ts-alerting-types'; import { useDispatch } from 'react-redux'; @@ -200,12 +200,17 @@ export const useAlertsByStatus: UseAlertsByStatus = ({ } }, [skip, refetchQuery]); - useQueryInspector({ - deleteQuery, - inspect: { + const inspect = useMemo( + () => ({ dsl: [request], response: [response], - }, + }), + [request, response] + ); + + useQueryInspector({ + deleteQuery, + inspect, refetch, setQuery, queryId,