yjs / y-quill

Quill Editor binding for Yjs
https://demos.yjs.dev/quill/quill.html
MIT License
80 stars 18 forks source link

new QuillBinding deletes all previous content from the quill editor #11

Closed Marius-Romanus closed 2 years ago

Marius-Romanus commented 2 years ago

Checklist

Describe the bug Hello, new QuillBinding deletes all previous content from the quill editor

To Reproduce Steps to reproduce the behavior:

  1. Go to https://github.com/yjs/yjs-demos download the project, go to yjs-demos-main/quill folder and install the dependencies
  2. add for example editor.insertText(0, 'Hello', 'bold', true); before of: const binding = new QuillBinding(ytext, editor, provider.awareness)

Expected behavior new QuillBinding should not delete the previous content of the Quill, since a new websocket connection cannot be created after adding the content of the Quill.

Environment Information Chrome Node: v16.14.0 y-protocols: 1.0.5 y-quill: 0.1.4 y-websocket: 1.4.3 yjs: 13.5.35

Additional context

What I am trying to do is connect to the socket only when there is more than one user in the same editor, and thus avoid unnecessary sending to the server through websocket. When there is only one user I can put the content, but as soon as more users come in and I try to connect them with new QuillBinding all the Quill text is deleted.

Thank you very much for all the work you do :)

Edit: Another example is using ngx-quill in Angular, putting the [(ngModel)]="data" and putting new QuillBinding(ytext, editor, provider.awareness) in the ngOnInit removes all the text.

dmonad commented 2 years ago

Hi @Marius-Romanus,

We could simply insert the text from the editor to the Yjs document before we bind Yjs to the editor. However, then every new client would insert the "initial content" (e.g. the content defined by the Angular model) which is probably not what you want as it would lead to duplicate content.

There is basically no way to implement what you are asking and end up with meaningful results. This approach would always lead to duplication of content. Hence we enforce that the initial state is always empty so that joining clients never accidentally insert the "initial content".

If you have suggestions how this could work, feel free to discuss. I'm closing this for now.

What I am trying to do is connect to the socket only when there is more than one user in the same editor, and thus avoid unnecessary sending to the server through websocket. When there is only one user I can put the content, but as soon as more users come in and I try to connect them with new QuillBinding all the Quill text is deleted.

Yjs is network agnostic. Most networks can fragment and it might be hard to determine if there is already a client somewhere online. Furthermore, it is basically impossible to implement a proper locking approach for web clients that can determine who should initialize content. Hence, I highly recommend generating a Yjs document even if it is not a collaborative session. Simplify your data flow and make sure that the base-case works. It doesn't make sense to optimize non-collaborative sessions because collaborative sessions have many advantages (e.g. auto-save to the backend, syncing only small incremental updates, offline support, ..).