yjs / y-prosemirror

ProseMirror editor binding for Yjs

Home Page:https://demos.yjs.dev/prosemirror/prosemirror.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No merge updates when deleting content

QingWei-Li opened this issue · comments

Please save me some time and use the following template. In 90% of all issues I can't reproduce the problem because I don't know what exactly you are doing, in which environment, or which y-* version is responsible. Just use the following template even if you think the problem is obvious.

Checklist

Describe the bug

Maybe the update generated by this plugin cannot be merged.

To Reproduce

  1. enter anything
  2. empty content
  3. repeat the above steps, the update size will continue to increase

https://codesandbox.io/s/y-promirror-bug-j73qe

Expected behavior

The initial content size and the deleted content size should be the same or similar.

Screenshots

This number is the update binary size

Initial Content Updated Deleted

image

image

image

Environment Information

  • Browser / Node.js [e.g. Chrome, Firefox, Node.js]
  • Yjs version and the versions of the y-* modules you are using [e.g. yjs v13.0.1, y-webrtc v1.2.1]. Use npm ls yjs to find out the exact version you are using.

Additional context
Add any other context about the problem here.

Hi @QingWei-Li,

this is the expected behavior. Yjs implements a CRDT that significantly reduces the size when content is deleted. The document-size will reduce further when you reload the window (the UndoManager keeps some meta information in the document that can normally be deleted). But it needs to retain some information about the history of the document in order to resolve conflicts with other peers. How should the local client otherwise know whether it received the content "3333333.." already or whether it should apply the same update again?

An increase of 13 bytes seems reasonable to me. So this is likely not a bug.

Yjs has the best size-reduction (garbage collection) approach that I found in any production CRDT. I published a blog post about the optimizations here: https://blog.kevinjahns.de/are-crdts-suitable-for-shared-editing/

I need persistent data. The current situation may cause the content size to continue to increase, even if the content is empty.

Is there any way to get only the update of the current content without history? I want to get the smallest size update to overwrite the stored data.

That would lead to conflicts when you sync with peers from an older session. This question comes up quite a lot. I highly recommend to simply store the document update as is. As the blog article explains, the size of the document grows very very slowly and even uses compression to reduce the size.

If you still want to overwrite history and start fresh, you could simply store the ProseMirror JSON instead of the Yjs document. But then you can't merge anymore (which is why you should store the Yjs update instead).