From 2a20a43ba7cf24c31b3c6ff5c6239691baff3ee6 Mon Sep 17 00:00:00 2001 From: peterkogo Date: Sat, 26 Sep 2026 12:00:54 +0200 Subject: [PATCH] fix(websocket): use browser-valid close codes Replace close code 1001 with 1000 in offline and heartbeat timeout handlers. Browser WebSocket.close() rejects 1001, preventing the socket from closing and blocking reconnection. --- packages/loro-websocket/src/client/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/loro-websocket/src/client/index.ts b/packages/loro-websocket/src/client/index.ts index 47d7982..37e5ca0 100644 --- a/packages/loro-websocket/src/client/index.ts +++ b/packages/loro-websocket/src/client/index.ts @@ -581,7 +581,7 @@ export class LoroWebsocketClient { if (this.shouldReconnect) { this.setStatus(ClientStatus.Disconnected); try { - this.ws?.close(1001, "Offline"); + this.ws?.close(1000, "Offline"); } catch { } } }; @@ -1396,7 +1396,7 @@ export class LoroWebsocketClient { this.awaitingPongSince = now; if (this.missedPongs >= 2) { try { - this.ws?.close(1001, "ping_timeout"); + this.ws?.close(1000, "ping_timeout"); } catch (err) { this.logCbError("pingTimer close", err); }