From 8e95f137938289087054cc83508f960a96112598 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Thu, 13 Nov 2025 20:25:18 -0500 Subject: [PATCH] fix: Multiplayer close retry (#10638) --- .../Document/components/MultiplayerEditor.tsx | 6 +++- shared/collaboration/CloseEvents.ts | 28 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/app/scenes/Document/components/MultiplayerEditor.tsx b/app/scenes/Document/components/MultiplayerEditor.tsx index 2e1ddf7937..c7ce44520c 100644 --- a/app/scenes/Document/components/MultiplayerEditor.tsx +++ b/app/scenes/Document/components/MultiplayerEditor.tsx @@ -157,7 +157,11 @@ function MultiplayerEditor({ onSynced, ...props }: Props, ref: any) { provider.on("close", (ev: MessageEvent) => { if ("code" in ev.event) { - provider.shouldConnect = false; + // Note other close code are handled internally by the library + if (ev.event.code === EditorUpdateError.code) { + provider.shouldConnect = false; + } + ui.setMultiplayerStatus("disconnected", ev.event.code); if (ev.event.code === EditorUpdateError.code) { diff --git a/shared/collaboration/CloseEvents.ts b/shared/collaboration/CloseEvents.ts index 58f0a3b248..2f794404aa 100644 --- a/shared/collaboration/CloseEvents.ts +++ b/shared/collaboration/CloseEvents.ts @@ -1,24 +1,52 @@ +/** + * The server is terminating the connection because a data frame was received + * that is too large. + * See: https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code + */ export const DocumentTooLarge = { code: 1009, reason: "Document Too Large", }; +/** + * Similar to AuthorizationFailed, but specifically for use when authentication is required and has + * failed or has not yet been provided. + */ export const AuthenticationFailed = { code: 4401, reason: "Authentication Failed", }; +/** + * The request contained valid data and was understood by the server, but the server + * is refusing action. + */ export const AuthorizationFailed = { code: 4403, reason: "Authorization Failed", }; +/** + * The server is refusing to process the request because there are too many connections + * to the given document. + */ export const TooManyConnections = { code: 4503, reason: "Too Many Connections", }; +/** + * The client must update their editor to continue collaborating. + */ export const EditorUpdateError = { code: 4999, reason: "Editor Update Required", }; + +/** + * The server timed out waiting for the request. + */ +export const ConnectionTimeout = { + code: 4408, + reason: "Connection Timeout", +};