From 220bb31f0c40e706309937cb5a2187dc1ac2a7a4 Mon Sep 17 00:00:00 2001 From: Tilman Vatteroth Date: Fri, 14 Apr 2023 18:25:53 +0200 Subject: [PATCH] fix: disconnect message transporter on editor leave Signed-off-by: Tilman Vatteroth --- .../editor-pane/hooks/yjs/use-realtime-connection.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frontend/src/components/editor-page/editor-pane/hooks/yjs/use-realtime-connection.ts b/frontend/src/components/editor-page/editor-pane/hooks/yjs/use-realtime-connection.ts index dacdd29c6..a9ec4bc95 100644 --- a/frontend/src/components/editor-page/editor-pane/hooks/yjs/use-realtime-connection.ts +++ b/frontend/src/components/editor-page/editor-pane/hooks/yjs/use-realtime-connection.ts @@ -94,6 +94,8 @@ export const useRealtimeConnection = (): MessageTransporter => { return () => window.removeEventListener('beforeunload', disconnectCallback) }, [messageTransporter]) + useEffect(() => () => messageTransporter.disconnect(), [messageTransporter]) + useEffect(() => { const connectedListener = messageTransporter.doAsSoonAsReady(() => setRealtimeConnectionState(true)) const disconnectedListener = messageTransporter.on('disconnected', () => setRealtimeConnectionState(false), {