yjs / y-prosemirror

ProseMirror editor binding for Yjs
https://demos.yjs.dev/prosemirror/prosemirror.html
MIT License
328 stars 115 forks source link

YJS doc is out of sync with ProseMirror doc #133

Closed ocavue closed 1 year ago

ocavue commented 1 year ago

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

After some specially updates, the ProseMirror's state and the YJS state are out of sync. These two store different content. Some text inside the YJS state disappears unexpectedly.

To Reproduce

Steps to reproduce the behavior:

  1. Clone https://github.com/issueset/y-prosemirror-mismatch-bug
  2. Run pnpm install
  3. Run pnpm dev to start a dev server. Open the web page in the browser
  4. Click the click button three times. Wait for 2 seconds between two clicks.
  5. You will see the these content in the console:
[after 1th click]    yjs and pm is match :)  doc(blockquote(paragraph("A")), blockquote(paragraph("B"), blockquote(paragraph), blockquote(paragraph("C")), blockquote(paragraph("D"))))
[after 2th click]    yjs and pm is match :)  doc(blockquote(paragraph("A")), blockquote(paragraph("B")), blockquote(paragraph, blockquote(paragraph("C")), blockquote(paragraph("D"))))
[after 3th click]    yjs and pm is mismatch :(
[after 3th click]    yjs:    doc(blockquote(paragraph("A")), blockquote(paragraph, blockquote(paragraph), blockquote(paragraph("C")), blockquote(paragraph("D"))))
[after 3th click]    pm:     doc(blockquote(paragraph("A")), blockquote(paragraph("B"), blockquote(paragraph), blockquote(paragraph("C")), blockquote(paragraph("D"))))

Notice that text B is still on the screen, but disappears in the YJS state.

Expected behavior

The content inside YJS and PM should not mismatch

Screenshots

https://user-images.githubusercontent.com/24715727/229290331-7c949389-37fe-4823-bb59-b580cc6f8ea3.mp4

Environment Information

ocavue commented 1 year ago

@dmonad This bug like a serious one that causes some data loss. Do you have any time to check it out?

dmonad commented 1 year ago

Thanks for the reproducible case! I fixed this in v1.2.1