Prosemirror build variations and yjs shared cursor

Hi. This is my first time here.
Is a wonderful project and I love the cursor sharing feature plugin on prosemirror.
The demo I got working well.


I found this Prosemirror variation that I was interested to use for my project. However it seems like they have modified many components inside so adding the plugin like the instruction didn’t work.

I tried for a long time to get it working, but somewhere in the package, it seems like the editorview has been reinitialized and the docview doesn’t render correctly the second time.
Since the yjs components are quite fragmented between y-prosemirror, y-websocket, yjs, y-protocols…etc, it was quite difficult to understand what was going wrong.

Sorry for such a big question, if anyone has dug deep in prosemirror before, could you point me in the right direction?

Thank you.

Welcome @ted_chou12!

Reading the first error message "unexpected content type in insert operation" I guess that their editor really works quite differently. You should be able to debug this by setting breakpoints. But from the looks of it you’d need to adapt y-prosemirror to work with licit.

So when debugging this issue, you only need to know about y-prosemirror and the yjs module.

yjs is a collection of “shared types” that automatically sync. It has many plugins for doing different things:
• y-websocket connects through a websocket server (internally communicating using y-protocols).
• y-prosemirror is an editor binding that syncs the prosemirror editor using Yjs data types. It literally syncs document updates between prosemirror and Yjs.

1 Like

Well, I don’t either understand that error but I get the same one as I try to locally run y-prosemirror and link it to my PM app. I wonder if it has something to do with the local dependencies of y-prosemirror conflicting with the other instances of the same libraries. It seems I have to have yjs and y-protocols installed as a dev dependency for the local y-prosemirror to find them. So I can’t try (or maybe there’s some trick) to use the same yjs and y-protocols and see if the bug persists.

Do you @dmonad know does yjs work if there’s two instances of the library loaded? Even if they are the same versions? At least React doesn’t work with a similar setup, I know having banged my head around that bug as well. I forget though what I did to solve that problem.

Hah, using this trick javascript - Duplicate ReactJS import issue when using npm link to test component before publishing as npm package - Stack Overflow I linked the yjs package inside my local y-prosemirror node_modules and the error is gone! So I think that “Unexpected content type in insert operation” is actually an error about two loaded yjs instances. Maybe there ought to be a check and specific error thrown for that? Similar how React or prosemirror-model does it. Although I think prosemirror-model handles this case as long as the versions are the same.

EDIT: Okay I made a PR that fixes another error that happens despite of this linking. What’s your opinion @dmonad about this? Certainly it would be nice to use instanceof but it seems there ought to be an error about two loaded Yjs instances or proper handling of this odd edge-case.

All right, it seems the linking is quite flaky business and on second try it seems also this second error is avoidable. And as was said in the PR, the constructor name check is slower than instanceof - good to know that. Sorry to have wasted maintainer’s time with this but hopefully somebody will avoid some head scratches from now on.

Although as I now ctrl-f’d the file, there are few places where a constructor comparison is used eg struct.constructor === Y.Item instead of instanceof check. I assume they could be switched to a instanceof operation but don’t know what are their implications - probably plus-minus-zero.