fix: use correct state when doc changed externally #1646
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There is a bug in suggestion plugin since Tiptap v1 when you use Collaboration and Mention together. It is bit edge case, but we actually ran into it in prod.
Open 2 editors (using collab)
Editor1 (user1): type some text and then enter Mention
Editor2 (user2): type/paste text anywhere before user1’s position
Editor1 (user1): confirms mention
Mention is at wrong position (replaces text at wrong position)
Reason:
When you use mention locally, from variables “handleStart, handleChange, handleExit“ only 1 is true (as it goes: start->change->...->change->exit).
When text in front of mention is changed in collab, it is not considered change (handleChange==false) as query is the same. Instead of it handleExit==true, handleStart==true and handleChange==false which cause that onStart is called with props from “prev” state instead of “next”.
When typing, the position is wrong by 1:
When pasting text, it is wrong by the length of pasted text: