yjs / y-monaco

Monaco editor bindings for Yjs
MIT License
168 stars 33 forks source link

Monaco ITextModel Out of Sync #7

Closed raedle closed 3 years ago

raedle commented 3 years ago

Checklist

Describe the bug Collaboratively editing in Monaco can break the ITextModel content (see screencast). It is reproducible if messages sent by the y-websocket are artificially delayed.

Note: the YText shared data type converges correctly. It's the Monaco editor that's not correctly reflecting the state of the shared type (see second screencast).

To Reproduce Steps to reproduce the behavior:

  1. Clone yjs-demos project to yjs-demos
  2. (cd yjs-demos/demo-server && npm install)
  3. (cd yjs-demos/monaco && npm install)
  4. (cd yjs-demos/demo-server && npm install lib0)
  5. Copy y-websocket/bin/utils.js to yjs-demos/demo-server/utils.js
  6. Copy y-websocket/bin/callback.js to yjs-demos/demo-server/callback.js
  7. Change const setupWSConnection = require('y-websocket/bin/utils.js').setupWSConnection in yjs-demos/demo-server/demo-server.js to const setupWSConnection = require('./utils.js').setupWSConnection
  8. Wrap send in utils.js in a setTimeout with 15000 ms (https://github.com/yjs/y-websocket/blob/9fd8f41fa8f1e29e3d98e6de8156b4650a89c7f1/bin/utils.js#L217) to artificially delay sending messages to peer clients.
  9. (cd yjs-demos/demo-server && npm start)
  10. Change the WebsocketProvider in yjs-demos/monaco/monaco.js to connect to your local websocket server (i.e. const provider = new WebsocketProvider('ws://localhost:8080', 'monaco-demo', ydoc)
  11. (cd yjs-demos/monaco && npm start)
  12. Open Chrome and Firefox and navigate to http://localhost:8081/monaco/monaco.html in both browsers
  13. Edit in one Monaco editor (similar to what is shown in the screencast) and once the updates come in in the other Monaco editor, start editing concurrently.

Expected behavior It is expected that both Monaco editors show the same content.

Screenshot

yjs-monaco

Screencast https://user-images.githubusercontent.com/489051/103810010-583c2400-500f-11eb-99f2-35e58e5c9d70.mp4

Screencast (with YText content logged to console) https://user-images.githubusercontent.com/489051/103834425-36a36280-5038-11eb-9456-d528c5c789e7.mp4

Environment Information

dmonad commented 3 years ago

Thank you for this detailed issue description. I was finally able to reproduce the issue reliably.

I merged your PR that fixes this issue. I also bumped the dependencies and allowed for current versions of the monaco editor.

The fix is published in y-monaco@0.1.2.