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) <noreply@anthropic.com>
This commit is contained in:
John McLear 2026-04-05 09:45:50 +01:00
parent 09d81c01a7
commit d6a4497015

View File

@ -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) => {