From 1938b6eefe5c05d63ba77b1bbe9c91bec5e46a57 Mon Sep 17 00:00:00 2001 From: Erik Michelson Date: Sat, 27 Aug 2022 18:29:51 +0200 Subject: [PATCH] fix(websocket): error when leaving realtime-note When a user left a realtime-note, the awareness tried to send events even after the socket was closed, resulting in the app crashing. This fix adds the check that the socket is still open before sending any messages. Signed-off-by: Erik Michelson --- .../editor-page/editor-pane/hooks/yjs/websocket-connection.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/editor-page/editor-pane/hooks/yjs/websocket-connection.ts b/src/components/editor-page/editor-pane/hooks/yjs/websocket-connection.ts index 085fa6136..ef412140e 100644 --- a/src/components/editor-page/editor-pane/hooks/yjs/websocket-connection.ts +++ b/src/components/editor-page/editor-pane/hooks/yjs/websocket-connection.ts @@ -51,7 +51,7 @@ export class WebsocketConnection extends WebsocketTransporter { private bindYDocEvents(doc: Doc): void { doc.on('destroy', () => this.disconnect()) doc.on('update', (update: Uint8Array, origin: unknown) => { - if (origin !== this && this.isSynced()) { + if (origin !== this && this.isSynced() && this.isWebSocketOpen()) { this.send(encodeDocumentUpdateMessage(update)) } })