-
Notifications
You must be signed in to change notification settings - Fork 12
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
Endless updating when using multiple browser windows #1
Comments
@ecssolutions This is because the plugin listens to the editor.on('NodeChange', (event: Event) => {
const colab = collaborativeMap.get(editor.getParam('selector'));
const user: User = JSON.parse(JSON.stringify(editor.getParam('budwriter')));
if (colab) {
colab.updateContent(event);
colab.onListen(event, user);
}
}); I removed this part, and we can add some other listeners we need. like: editor.on('blur', (event: Event) => {
const colab = collaborativeMap.get(editor.getParam('selector'));
const user: User = JSON.parse(JSON.stringify(editor.getParam('budwriter')));
if (colab) {
colab.updateContent(event);
colab.onListen(event, user);
}
}); After doing that, you can always run |
After trying to make this code to work in real world, I would say following: You have to listen for both The problem you're seeing is actually caused by the overly simple protocol used in this plugin. It's a race condition and I fail to see anything in the protocol that could avoid the problem. If I've understood correctly, the issue is triggered at least in following case:
And depending on the events that the currently used browser fires on cursor movement or content changes, the protocol may end up sending duplicate or tripple messages for each event. I think this part could be fixed by adding a throttle limiter to event stream (I did at a limiter that it seemed to help a bit but didn't fix all the problems with cursor placement). However, the protocol has even bigger problems. For example, if X and Y write (or otherwise execute any change to the content) at the same time, both will send message If you test this code with a single computer only, it cannot show the most problems because you can have just one active caret and one focus position on most operating systems and as a result, you cannot see the case where both are: sending a change at the same time (here "same time" is closer in time than the sum of ping between the clients and the server). And if there are more than 2 authors, the problem will just get worse because the end result depends on timing of all the events over all the clients and if different authors have different browsers (e.g. Firefox vs Chrome vs iPad Safari) the timing of events will be different for each client even if they were in the same network. The sad fact is that you would really need to implement full CRDT algorithm with the cursor movement implemented on top of CRDT syncronization, too, if you want a collaborative editor without edge cases like this. |
Hi,
First of all very cool plugin!
I just encountered one problem, wen the editor is opened in multiple windows, when the cursor is set both editors, it will trigger an endless loop of update content and setting cursor at the beginning of the editor. The loop can be stopped when the focus was moved out editor.
This can be reproduced by opening 2 windows of your codepen page https://codepen.io/thealmarques/full/YzqOrWV
The text was updated successfully, but these errors were encountered: