From 7c69c69728f81c8a1925ac54ca3dc5ebb04509b5 Mon Sep 17 00:00:00 2001 From: RachelElysia <71795832+RachelElysia@users.noreply.github.com> Date: Tue, 20 May 2025 13:34:08 -0400 Subject: [PATCH] Fleet UI: Dashboard > Software fix cached data not updating UI (#29288) --- .../pages/DashboardPage/DashboardPage.tsx | 54 ++++++++++--------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/frontend/pages/DashboardPage/DashboardPage.tsx b/frontend/pages/DashboardPage/DashboardPage.tsx index c609c0255a..d8153acc59 100644 --- a/frontend/pages/DashboardPage/DashboardPage.tsx +++ b/frontend/pages/DashboardPage/DashboardPage.tsx @@ -331,34 +331,38 @@ const DashboardPage = ({ router, location }: IDashboardProps): JSX.Element => { enabled: isRouteOk && isSoftwareEnabled, keepPreviousData: true, staleTime: 30000, // stale time can be adjusted if fresher data is desired based on software inventory interval - onSuccess: (data) => { - const hasSoftwareResults = !!data.software && data.software.length > 0; - - if (hasSoftwareResults) { - setSoftwareTitleDetail && - setSoftwareTitleDetail( - - Fleet periodically queries all hosts to -
- retrieve software. Click to view -
- hosts for the most up-to-date lists. - - } - /> - ); - setShowSoftwareCard(true); - } else if (!isViewingVulnerableSoftware) { - setShowSoftwareCard(false); - } - // For vulnerable software with no results, the count query will handle showing the card. - }, + // Don't use onSuccess for UI state: it won't run for cached data, only after a new fetch } ); + // Keeps UI state in sync with both cached and freshly fetched query results + useEffect(() => { + const hasSoftwareResults = + !!software?.software && software.software.length > 0; + + if (hasSoftwareResults) { + setShowSoftwareCard(true); + setSoftwareTitleDetail( + + Fleet periodically queries all hosts to +
+ retrieve software. Click to view +
+ hosts for the most up-to-date lists. + + } + /> + ); + } else if (!isViewingVulnerableSoftware) { + setShowSoftwareCard(false); + setSoftwareTitleDetail(null); + } + // For vulnerable software with no results, the count query will handle showing the card. + }, [software, isViewingVulnerableSoftware]); + // If viewing vulnerable software and no results are returned, // fetch the count of non-vulnerable software to decide if the card should be shown. const shouldFetchSoftwareCount =