From 0b5f7f3fcdeaee6f8f6bf158376a169668799d71 Mon Sep 17 00:00:00 2001 From: Curry Yang <1019yanglu@gmail.com> Date: Thu, 9 Jan 2025 14:24:54 +0800 Subject: [PATCH] close connections when organization change --- .../insomnia/src/ui/hooks/use-close-connection.ts | 11 ++++++++++- packages/insomnia/src/ui/routes/debug.tsx | 4 +++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/insomnia/src/ui/hooks/use-close-connection.ts b/packages/insomnia/src/ui/hooks/use-close-connection.ts index f6d9ad51805..c30cd8f8476 100644 --- a/packages/insomnia/src/ui/hooks/use-close-connection.ts +++ b/packages/insomnia/src/ui/hooks/use-close-connection.ts @@ -8,7 +8,7 @@ import { useInsomniaTabContext } from '../context/app/insomnia-tab-context'; import uiEventBus, { UIEventType } from '../eventBus'; // this hook is use for control when to close connections(websocket & SSE & grpc stream & graphql subscription) -export const useCloseConnection = () => { +export const useCloseConnection = ({ organizationId }: { organizationId: string }) => { const closeConnectionById = async (id: string) => { if (isGrpcRequestId(id)) { @@ -59,4 +59,13 @@ export const useCloseConnection = () => { uiEventBus.off(UIEventType.CHANGE_AVTIVE_ENV, handleActiveEnvironmentChange); }; }, [handleTabClose, handleActiveEnvironmentChange]); + + // close all connections when organizationId change + useEffect(() => { + return () => { + window.main.webSocket.closeAll(); + window.main.grpc.closeAll(); + window.main.curl.closeAll(); + }; + }, [organizationId]); }; diff --git a/packages/insomnia/src/ui/routes/debug.tsx b/packages/insomnia/src/ui/routes/debug.tsx index 248f65b1f62..058d74783c0 100644 --- a/packages/insomnia/src/ui/routes/debug.tsx +++ b/packages/insomnia/src/ui/routes/debug.tsx @@ -454,7 +454,9 @@ export const Debug: FC = () => { }, }); - useCloseConnection(); + useCloseConnection({ + organizationId, + }); const isRealtimeRequest = activeRequest &&