From 999ac6aeed562301b22b26eb171522e3c9fc395a Mon Sep 17 00:00:00 2001 From: Utkarsh patrikar <137105846+utkarsh232005@users.noreply.github.com> Date: Sat, 13 Jun 2026 19:08:37 +0530 Subject: [PATCH] Apply suggested fix to src/ui/WatchDashboard.tsx from Copilot Autofix Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> --- src/ui/WatchDashboard.tsx | 77 ++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/src/ui/WatchDashboard.tsx b/src/ui/WatchDashboard.tsx index 9b86270..987191a 100644 --- a/src/ui/WatchDashboard.tsx +++ b/src/ui/WatchDashboard.tsx @@ -45,54 +45,63 @@ export const WatchDashboard = () => { }, []); useEffect(() => { - const fetchPods = async () => { - try { - const p = await getRunningPods(); - setPods(p); + let isMounted = true; + let isFetching = false; + + const fetchData = async () => { + if (isFetching) return; + isFetching = true; + + const [podsResult, containersResult, k8sStatsResult, dockerStatsResult] = await Promise.allSettled([ + getRunningPods(), + getRunningContainers(), + getK8sClusterStats(), + getDockerSystemStats() + ]); + + if (!isMounted) { + isFetching = false; + return; + } + + if (podsResult.status === 'fulfilled') { + setPods(podsResult.value); setError(prev => prev?.type === 'k8s' ? null : prev); - } catch (err) { - setError({ type: 'k8s', message: (err as Error).message }); + } else { + setError({ type: 'k8s', message: (podsResult.reason as Error).message }); } - }; - const fetchContainers = async () => { - try { - const c = await getRunningContainers(); - setContainers(c); + if (containersResult.status === 'fulfilled') { + setContainers(containersResult.value); setError(prev => prev?.type === 'docker' ? null : prev); - } catch (err) { - setError({ type: 'docker', message: (err as Error).message }); + } else { + setError({ type: 'docker', message: (containersResult.reason as Error).message }); } - }; - const fetchK8sStats = async () => { - try { - const stats = await getK8sClusterStats(); - setK8sStats(stats); - } catch (err) { + if (k8sStatsResult.status === 'fulfilled') { + setK8sStats(k8sStatsResult.value); + } else { setK8sStats(null); } - }; - const fetchDockerStats = async () => { - try { - const stats = await getDockerSystemStats(); - setDockerStats(stats); - } catch (err) { + if (dockerStatsResult.status === 'fulfilled') { + setDockerStats(dockerStatsResult.value); + } else { setDockerStats(null); } - }; - const fetchData = () => { - fetchPods(); - fetchContainers(); - fetchK8sStats(); - fetchDockerStats(); + isFetching = false; }; - fetchData(); - const interval = setInterval(fetchData, 3000); - return () => clearInterval(interval); + void fetchData(); + const interval = setInterval(() => { + void fetchData(); + }, 3000); + + return () => { + isMounted = false; + clearInterval(interval); + }; }, []); const isCompact = columns < 80;