summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhaoyuren <13851610112@163.com>2026-03-15 19:13:57 -0500
committerhaoyuren <13851610112@163.com>2026-03-15 19:13:57 -0500
commitc667ff6a58b36b67bb92ff5a20df646e0777c6d5 (patch)
tree45d4fb4e043b98f706570a1aae58ad20c6d08f84 /src
parent250c3c6cebe68a8a7e37032b550f1bd1c378508d (diff)
Fix OT ack/error swallowed when doc transitions to editor mode
When addEditorDoc is called while the bridge has in-flight OT ops (awaitingConfirm), the ack/error response was ignored because handleOtUpdate/handleOtError skipped editor docs entirely. This left the bridge's OtClient stuck and the edit appeared lost until removeEditorDoc re-discovered the discrepancy. Fix: always process acks regardless of editor doc status, and only skip OT errors for editor docs when the bridge has no OtClient. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'src')
-rw-r--r--src/main/fileSyncBridge.ts14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/main/fileSyncBridge.ts b/src/main/fileSyncBridge.ts
index 296ed12..c9397f0 100644
--- a/src/main/fileSyncBridge.ts
+++ b/src/main/fileSyncBridge.ts
@@ -282,8 +282,11 @@ export class FileSyncBridge {
}
}
- // For non-editor docs, handle ack (op with no ops array = ack for our own op)
- if (!this.editorDocs.has(docId) && !update.op) {
+ // Handle ack — process even for editor docs so the bridge's OtClient
+ // can finish pending ops (e.g. ops sent just before addEditorDoc was called).
+ // Without this, the OtClient stays stuck in awaitingConfirm and the ops
+ // appear lost until removeEditorDoc re-discovers the discrepancy.
+ if (!update.op) {
const otClient = this.otClients.get(docId)
if (otClient) {
otClient.onAck()
@@ -298,7 +301,12 @@ export class FileSyncBridge {
const error = args[0] as { doc?: string; message?: string } | undefined
if (!error?.doc) return
const docId = error.doc
- if (this.editorDocs.has(docId)) return // renderer handles editor docs
+
+ // Don't skip editor docs entirely — the bridge may have sent ops just before
+ // addEditorDoc was called, and the error response arrives after. If we skip,
+ // the bridge's OtClient stays stuck and the ops are silently lost.
+ // Only skip if the bridge has no OtClient for this doc.
+ if (this.editorDocs.has(docId) && !this.otClients.has(docId)) return
const relPath = this.docPathMap[docId]
if (!relPath) return