From f08a1686d22b6fef835681e314a22956c1f786b5 Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 18 Nov 2024 12:00:11 +0100 Subject: [PATCH] fix(sync): process document state from push response Do not process document state from create response. During create the editor has not been initialized fully and the cursor position is 0 - which is invalid as it is not inside a node with inline content. (It is inside the doc before the initial paragraph.) This also allows processing document state later on in order to recover from out of sync situations. But we do not make use of that yet. Signed-off-by: Max --- src/services/SyncService.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/services/SyncService.js b/src/services/SyncService.js index 5c0c50f9f19..e31e51804e8 100644 --- a/src/services/SyncService.js +++ b/src/services/SyncService.js @@ -122,16 +122,6 @@ class SyncService { this.baseVersionEtag = this.#connection.document.baseVersionEtag this.emit('opened', this.connectionState) this.emit('loaded', this.connectionState) - const documentState = this.connectionState.documentState - if (documentState) { - const initialStep = documentStateToStep(documentState) - this.emit('sync', { - version: this.version, - steps: [initialStep], - document: this.#connection.document, - }) - } - return this.connectionState } @@ -186,7 +176,15 @@ class SyncService { } return this.#connection.push(sendable) .then((response) => { - const { steps } = response.data + const { steps, documentState } = response.data + if (documentState) { + const documentStateStep = documentStateToStep(documentState) + this.emit('sync', { + version: this.version, + steps: [documentStateStep], + document: this.#connection.document, + }) + } this.pushError = 0 this.sending = false if (steps?.length > 0) {