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

y-prosemirror fires two updates for each change #121

Closed
2 tasks done
ocavue opened this issue Jun 17, 2022 · 6 comments
Closed
2 tasks done

y-prosemirror fires two updates for each change #121

ocavue opened this issue Jun 17, 2022 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@ocavue
Copy link
Contributor

ocavue commented Jun 17, 2022

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 updating y-prosemirror from 1.0.20 to 1.1.0, every keypress will trigger the update method for every plugin twice. This causes a lot of issues if a plugin want to compare the current state with the prev state.

To Reproduce

I wrote a minimal reproduction to show this issue. In this example, I have a ProseMirror plugin to show whether or not the cursor is changed in the last operation. The code of this plugin is in prosemirror.ts.

  1. Open https://stackblitz.com/github/ocavue/y-prosemirror-playground/tree/issue-double-update-1.0.20 and https://stackblitz.com/github/ocavue/y-prosemirror-playground/tree/issue-double-update-1.1.2. They have the same code but with different versions of y-prosemirror
  2. Click the Disconnect button. We don't want them to affect each other.
  3. Typing something.
  4. In the 1.0.20 window, you will see Is your cursor changed? true. While in the 1.1.2 window, you will see false.
  5. Open the console. Every keypress will trigger one plugin update in 1.0.20, but two updates in 1.1.2.

Expected behavior

Every keypress will only trigger one plugin update, as what we used to have in y-prosemirror 1.0.20

Screenshots

https://share.cleanshot.com/NJlBDh

Additional context

In commit 2d06ece, pluginState.doc.transact was added inside syncPlugin's update function. Calling pluginState.doc.transact will trigger _typeChanged because it has been observed. tr.replace will be called in _typeChanged, which causes the second update.

@ocavue ocavue added the bug Something isn't working label Jun 17, 2022
@ocavue
Copy link
Contributor Author

ocavue commented Jun 17, 2022

This issue should share the same underlying reason as #113

ocavue added a commit to team-reflect/y-prosemirror that referenced this issue Jun 17, 2022
@jamesopti
Copy link

jamesopti commented Jun 20, 2022

+1 - It appears now that due to the same commit, NodeSelections are converted to TextSelections anytime the document changes, as the _typeChanged mux function ends up getting called and actually replaces the entire document (like a remote change).

@jamesopti
Copy link

Any updates on this one?

@maccman
Copy link

maccman commented Aug 24, 2022

This one seems quite important @dmonad - and I think @ocavue has a PR that fixes it.

@dmonad dmonad closed this as completed in 5f55313 Aug 24, 2022
@dmonad
Copy link
Member

dmonad commented Aug 24, 2022

Fixed and released 👍

@maccman
Copy link

maccman commented Aug 24, 2022

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

4 participants