From d6a4497015362425e41aedb08a821756d141b423 Mon Sep 17 00:00:00 2001 From: John McLear Date: Sun, 5 Apr 2026 09:45:50 +0100 Subject: [PATCH] fix: defer handleUserChanges on connect to avoid editor init race Calling handleUserChanges() synchronously in setUpSocket() caused "Cannot read properties of null (reading 'changeset')" because the editor isn't fully initialized on first connect. Deferred with setTimeout(500ms) to allow initialization to complete. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/static/js/collab_client.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/static/js/collab_client.ts b/src/static/js/collab_client.ts index 62cfdabf1..bd5403d02 100644 --- a/src/static/js/collab_client.ts +++ b/src/static/js/collab_client.ts @@ -155,11 +155,12 @@ const getCollabClient = (ace2editor, serverVars, initialUserInfo, options, _pad) initialStartConnectTime = Date.now(); - // Flush any pending local changes immediately after (re)connect. + // Flush any pending local changes after (re)connect. // Without this, changes made while disconnected are not sent to the // server until the user makes another edit. + // Deferred to allow the editor to finish initialization on first connect. // See https://github.com/ether/etherpad-lite/issues/5108 - handleUserChanges(); + setTimeout(handleUserChanges, 500); }; const sendMessage = (msg) => {