From 8662a1034ab7769b0b0273aaa28af334c3b7f047 Mon Sep 17 00:00:00 2001 From: Rishabh Tripathi <161459068+rishabh8870@users.noreply.github.com> Date: Tue, 16 Dec 2025 22:53:27 +0530 Subject: [PATCH] Handle before unload event for chat mode Add event listener to prevent data loss on unload if in chat mode. --- client/src/App.jsx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/client/src/App.jsx b/client/src/App.jsx index 59f051048..bf02e6648 100644 --- a/client/src/App.jsx +++ b/client/src/App.jsx @@ -45,6 +45,23 @@ function App() { updateOnlineStatus(onlineStatus); }, [onlineStatus]); + useEffect(() => { + const handleBeforeUnload = (event) => { + // Check if user is in chat mode (on /founduser route) + const isInChat = window.location.pathname === '/founduser'; + if (isInChat) { + event.preventDefault(); + event.returnValue = ''; + return ''; + } + }; + + window.addEventListener('beforeunload', handleBeforeUnload); + return () => { + window.removeEventListener('beforeunload', handleBeforeUnload); + }; + }, []); + return (