Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some text is duplicated when two users concurrently make changes at the beginning of the same line #161

Closed
2 tasks done
MacroMackie opened this issue Jul 17, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@MacroMackie
Copy link

MacroMackie commented Jul 17, 2024

Checklist

Describe the bug
When using y-prosemirror, and two users make a few edits to a line at the exact same line, I sometimes see some text duplicated. (See attached video for more info).

To Reproduce
Steps to reproduce the behavior:

  • Have two users open a prosemirror editor (using y-prosemirror for collaborative editing)
  • They both place their cursors on the beginning of a line
  • They both make some edits
  • They make a second set of edits at the exact same time (the timing is a little tight)

You'll notice that one of the characters becomes duplicated.

Expected behavior
No duplication - some kind of tie-breaking logic is used to figure out which edits land on the left/right.

Screenshots

I've reproduced the issue on the y-prosemirror demo environment ( https://demos.yjs.dev/prosemirror/prosemirror.html )

CleanShot.2024-07-17.at.12.59.19.mp4

I've also been able to reproduce it in other prosemirror-based environments (e.g. TipTap - https://templates.tiptap.dev )

updated.mp4

Environment Information
I can reproduce in chrome (126.0.6478.127), as well as safari, and firefox.

Locally, I encountered this issue with:

  • @tiptap/core 2.5.1
  • y-prosemirror 1.2.9

Additional context
I've also created a pull-request here with a test case which seems to reproduce the issue - #160 ( I'm not too familiar with the y.js internals, so this might not be accurate. )

Let me know if you need any other information!

@dmonad
Copy link
Member

dmonad commented Aug 5, 2024

I fixed the issue and will make a new release shortly.

The issue is related to an internal cleanup function. The first concurrent edits create two Y.Text elements. The second concurrent edit triggers a cleanup function where both clients want to move the content from the second Y.Text to the first. This leads to duplication.

I fixed the issue by forcing the author of the second Y.Text to move the content directly after it notices a concurrent edit.

This will be good enough for most cases. But for change-tracking, I might need to implement a better fix.

@dmonad dmonad closed this as completed Aug 5, 2024
@MacroMackie
Copy link
Author

Amazing - thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants