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

[Example Test Case] - Some text is duplicated when two users concurrently make changes at the beginning of the same line #160

Conversation

MacroMackie
Copy link

@MacroMackie MacroMackie commented Jul 17, 2024

Related to the issue described here:

I've attempted to create a test case which reproduces the described issue.

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

( Note that I'm not too familiar with the y.js internals, so the test may not be perfectly representative )

@MacroMackie MacroMackie changed the title Example Test Some text is duplicated when two users concurrently make changes on the same line Jul 17, 2024
@MacroMackie MacroMackie force-pushed the macromackie/collab-editing-bug-newlines branch from aedd3ba to 9e797f7 Compare July 17, 2024 20:04
Comment on lines +602 to +606
const initialContent = schema.node('doc', null, [
schema.node('paragraph', null, [schema.text('123')]),
schema.node('paragraph'),
schema.node('paragraph', null, [schema.text('456')])
])
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example doc with a newline in the middle

Comment on lines +621 to +622
const insertA = view1.state.tr.insertText('A', 6)
const insertX = view2.state.tr.insertText('X', 6)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I insert A and X
(Attempting to simulate two different editors)

Comment on lines +646 to +649
t.assert(
contentAfterFirstInsert === '<paragraph>123</paragraph><paragraph>AX</paragraph><paragraph>456</paragraph>' ||
contentAfterFirstInsert === '<paragraph>123</paragraph><paragraph>XA</paragraph><paragraph>456</paragraph>'
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Things look good at this point
(The test doesn't have a preference for which order wins the tiebreak)

Comment on lines +652 to +653
const insertB = view1.state.tr.insertText('B', 7)
const insertY = view2.state.tr.insertText('Y', 7)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another round of edits (using position 7, although there is probably a better way to do this (somewhat dependant on the earlier tiebreak?)

Comment on lines +677 to +684
// TODO: This is failing.
// contentAfterSecondInsert == <paragraph>123</paragraph><paragraph>ABXYX</paragraph><paragraph>456</paragraph>
// Note the duplication of `X`.

t.assert(
contentAfterSecondInsert === '<paragraph>123</paragraph><paragraph>ABXY</paragraph><paragraph>456</paragraph>' ||
contentAfterSecondInsert === '<paragraph>123</paragraph><paragraph>XYAB</paragraph><paragraph>456</paragraph>'
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate X character (this test is failing)

@MacroMackie MacroMackie marked this pull request as draft July 17, 2024 20:13
@MacroMackie MacroMackie changed the title Some text is duplicated when two users concurrently make changes on the same line [Example Test Case] - Some text is duplicated when two users concurrently make changes on the same line Jul 17, 2024
@MacroMackie MacroMackie changed the title [Example Test Case] - Some text is duplicated when two users concurrently make changes on the same line [Example Test Case] - Some text is duplicated when two users concurrently make changes at the beginning of the same line Jul 17, 2024
@dmonad dmonad closed this in 627b6b2 Aug 5, 2024
@dmonad
Copy link
Member

dmonad commented Aug 5, 2024

Thank you, this PR was immensely helpful!!

I fixed the issue and added a test case for it (based on your work).

@MacroMackie MacroMackie deleted the macromackie/collab-editing-bug-newlines branch August 5, 2024 16:26
nperez0111 pushed a commit to Pruxis/y-prosemirror that referenced this pull request Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants