Skip to content

fix(vfs): do not send an empty applyOtUpdate on save - #408

Open
RobertoReale wants to merge 1 commit into
overleaf-workshop:masterfrom
RobertoReale:fix/skip-empty-ot-update
Open

fix(vfs): do not send an empty applyOtUpdate on save#408
RobertoReale wants to merge 1 commit into
overleaf-workshop:masterfrom
RobertoReale:fix/skip-empty-ot-update

Conversation

@RobertoReale

Copy link
Copy Markdown

Fixes #403

Problem

VirtualFileSystem.writeFile sends the computed OT update unconditionally:

this.isDirty = (update.op && update.op.length) ? true : false;
await this.socket.applyOtUpdate(doc._id, update);

When the diff resolves to nothing (saving a document that did not really change), update.op is [] and the update is still emitted. The real-time service answers the emit with an error object and sends forceDisconnect shortly after, so:

  • the raw payload reaches the user as Failed to save 'main.tex': Unable to write file ... ([object Object]);
  • the socket is dropped, reconnects, the save is retried, and the loop repeats.

Change

Skip the round-trip when the update carries no operation, reusing the isDirty flag computed on the line above. The local and remote caches are updated exactly as before, so a save with no changes is now a silent no-op.

Verification

Against overleaf.com with 0.15.10 + this patch: repeated Ctrl+S on an unchanged document no longer produces an error or a disconnect, and a save that does change the text still reaches the server (applyOtUpdateackotUpdateApplied, text updated live on overleaf.com).

When a document is saved without any real change, the computed diff has an
empty `op` array. The update is still sent, and the real-time service answers
with an error object and force-disconnects the client shortly after, so the
user sees `Unable to write file ... ([object Object])` followed by a
reconnection loop.

`isDirty` already records whether the update carries any operation: use it to
skip the round-trip entirely. The local/remote caches are updated as before.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Saving an unchanged document sends an empty applyOtUpdate: "Unable to write file ... ([object Object])" and forced disconnect

1 participant