Skip to content

Commit 758b978

Browse files
committed
Fix: Duplicated user during reconnect
1 parent 41a5148 commit 758b978

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

source/sharedb-ace-binding.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,17 +344,17 @@ class SharedbAceBinding {
344344
try {
345345
this.cursorManager?.removeCursor(id);
346346
// eslint-disable-next-line no-empty
347-
} catch {}
347+
} catch { }
348348

349349
try {
350350
this.selectionManager?.removeSelection(id);
351351
// eslint-disable-next-line no-empty
352-
} catch {}
352+
} catch { }
353353

354354
try {
355355
this.radarManager?.removeView(id);
356356
// eslint-disable-next-line no-empty
357-
} catch {}
357+
} catch { }
358358

359359
if (id in this.connectedUsers) {
360360
delete this.connectedUsers[id];
@@ -363,7 +363,9 @@ class SharedbAceBinding {
363363
return;
364364
}
365365

366-
this.connectedUsers[id] = update.user;
366+
if (!this.connectedUsers[id]) {
367+
this.connectedUsers[id] = update.user;
368+
}
367369

368370
if (this.cursorManager && update.cursorPos) {
369371
try {
@@ -464,6 +466,17 @@ class SharedbAceBinding {
464466
*/
465467
onRemoteReload = () => {
466468
this.logger.log('*remote*: reloading document');
469+
// Destroy local presence if it exists to prevent
470+
// submission of local presence again during initialization
471+
if (this.localPresence) {
472+
try {
473+
this.logger.log('*remote*: destroying local presence');
474+
this.localPresence.destroy();
475+
this.localPresence = undefined;
476+
} catch (error) {
477+
console.warn("Error destroying local presence:", error);
478+
}
479+
}
467480
this.setInitialValue();
468481
};
469482
}

0 commit comments

Comments
 (0)