From 140a63edf8121ca5eadafd407221febf2c2d7b48 Mon Sep 17 00:00:00 2001 From: shravanithouta108 Date: Tue, 21 Jul 2026 13:34:07 +0530 Subject: [PATCH 1/3] fix: stop dashboard polling after health failure and add manual retry --- frontend/src/pages/Dashboard.tsx | 76 ++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 34 deletions(-) diff --git a/frontend/src/pages/Dashboard.tsx b/frontend/src/pages/Dashboard.tsx index a7517d741..5ac79810d 100644 --- a/frontend/src/pages/Dashboard.tsx +++ b/frontend/src/pages/Dashboard.tsx @@ -181,6 +181,7 @@ export default function Dashboard() { const [error, setError] = useState(null) const [backendConnected, setBackendConnected] = useState(null) const [lastSync, setLastSync] = useState(null) + const [healthFailed, setHealthFailed] = useState(false) const navigate = useNavigate() const applySummary = (data: Partial) => { @@ -190,43 +191,46 @@ export default function Dashboard() { } useEffect(() => { - let cancelled = false - - const load = async () => { - try { - await getHealth() - if (!cancelled) setBackendConnected(true) - } catch { - if (!cancelled) { - setBackendConnected(false) - setError('Unable to reach the SecuScan backend') - setLoading(false) - } - return - } + let cancelled = false + + const load = async () => { + if (healthFailed) return - getDashboardSummary() - .then((data) => { - if (cancelled) return - applySummary(data as Partial) - }) - .catch((err) => { - if (cancelled) return - setError(err.message) - }) - .finally(() => { - if (!cancelled) setLoading(false) - }) + try { + await getHealth() + if (!cancelled) setBackendConnected(true) + } catch { + if (!cancelled) { + setBackendConnected(false) + setHealthFailed(true) + setError('Unable to reach the SecuScan backend') + setLoading(false) + } + return } - load() - const interval = setInterval(load, 10000) + getDashboardSummary() + .then((data) => { + if (cancelled) return + applySummary(data as Partial) + }) + .catch((err) => { + if (cancelled) return + setError(err.message) + }) + .finally(() => { + if (!cancelled) setLoading(false) + }) + } - return () => { - cancelled = true - clearInterval(interval) - } - }, []) + load() + const interval = setInterval(load, 10000) + + return () => { + cancelled = true + clearInterval(interval) + } +}, [healthFailed]) const handleAbort = async (taskId: string) => { try { @@ -356,7 +360,11 @@ export default function Dashboard() { {error}. Please verify network connectivity.