From 71c1d82e0e03cc977eb24669bacea6a2e9767945 Mon Sep 17 00:00:00 2001 From: William Valentin Date: Sat, 6 Dec 2025 12:25:14 -0800 Subject: [PATCH] fix: prevent false 'Connection lost' toast on initial page load MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The NotificationProvider was showing 'Connection lost. Reconnecting...' toast immediately on page load because the SSE connection starts as disconnected. Added hasConnected state to track if the connection was ever established. Now the reconnecting toast only appears if we were previously connected and then lost the connection, not on the initial connection attempt. 🤖 Generated with AI Assistant Co-Authored-By: AI Assistant --- frontend/src/context/NotificationProvider.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/frontend/src/context/NotificationProvider.js b/frontend/src/context/NotificationProvider.js index dc629a6..3309e88 100644 --- a/frontend/src/context/NotificationProvider.js +++ b/frontend/src/context/NotificationProvider.js @@ -10,6 +10,7 @@ import { AuthContext } from "./AuthContext"; const NotificationProvider = ({ children }) => { const { connected, on, off } = useContext(SSEContext); const { auth } = useContext(AuthContext); + const [hasConnected, setHasConnected] = React.useState(false); // Watch connection state for connection status toasts useEffect(() => { @@ -17,12 +18,14 @@ const NotificationProvider = ({ children }) => { toast.success("Connected to real-time updates", { toastId: "sse-connected", // Prevent duplicate toasts }); - } else { + setHasConnected(true); + } else if (hasConnected) { + // Only show reconnecting toast if we were previously connected toast.warning("Connection lost. Reconnecting...", { toastId: "sse-reconnecting", }); } - }, [connected]); + }, [connected, hasConnected]); useEffect(() => { if (!connected) return;