From f9aa99a922fd25f784fb9ccd1ca2dcf96047d21e Mon Sep 17 00:00:00 2001 From: talksik Date: Mon, 9 May 2022 07:39:58 -0500 Subject: [PATCH] disconnect on component unmount --- packages/desktop/src/controller/lineDataProvider.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/desktop/src/controller/lineDataProvider.tsx b/packages/desktop/src/controller/lineDataProvider.tsx index 4d66af2..24cafcc 100644 --- a/packages/desktop/src/controller/lineDataProvider.tsx +++ b/packages/desktop/src/controller/lineDataProvider.tsx @@ -197,7 +197,7 @@ function useSocketHandler(linesData: MasterLineData[]) { $ws.io.on("close", () => { console.error( - "there was a problem with your app...connection closed likely due to idling" + "SOCKET | there was a problem with your app...connection closed likely due to idling or manual disconnect" ); toast.error( "SOCKETS | connection closed with websockets!!!! either reload app or manually reconnect here" @@ -214,6 +214,11 @@ function useSocketHandler(linesData: MasterLineData[]) { // this should overall remount this component currently which is what we want for new data queryClient.invalidateQueries("SERVER_CHECK"); }); + + // on unmounting this component, we want to disconnect + return () => { + $ws.disconnect(); + }; }, []); /** handle initial data coming in and creating the initial line map