Hi, I’m attaching collaborative editing library to ProseMirror, and the following problems arise.
- Client A edit the document, and broadcast edited range to other client.
- The broadcast function is called from
plugin.state.apply
- Client B receives changes and applies them to documents.
-
plugin.state.apply
called again when apply changes.
- Client A receives changes and applies them to documents… and step 2-3 repeat forever.
Is there any way to change the contents of the document without side effects? or Am I using something wrong? (I think I am, but I don’t know what it is)
The code of my plugin is like this.
{
state: {
apply(tr) {
if (tr.docChanged) {
broadcastChanges(foo(tr));
}
}
},
view(view) {
collabDocument.onChange((change) => {
if (client.id === change.user.id) {
return;
}
let { state } = view;
state = state.apply(state.tr.insertText(change.text, changes.from));
view.updateState(state);
});
},
}