Doc stop syncing after reconnect
Description I found a weird bug when editor stops syncing. This is especially huge problem because provider is connected and synced so I don't know how to find out user is not being synced. This happens when:
- you lose connection
- you make changes (this is important, if you do not make changes it actually works fine)
- you reconnect back to server
- not editor appears synced and connected but nothing is being saved to server
- (I do not use IndexedDB)
Steps to reproduce the bug Steps to reproduce the behavior:
- Open editor, type something
- Disable internet
- Type something in editor
- Wait 20-30s for connection timeout so you can see in console reconnect attempts
- Enable internet, editor successfully connects to server again (Provider is synced=true and status=connected)
- Type something -> no changes being saved to server
- Client is connected to server, server sends message to client every 15s (awareness I suppose) but server does not process any updates from client
- You close tab with editor and at the server you can see the connection was closed
Expected behavior When I do same thing with WebsocketProvider, it works.
Screenshot, video, or GIF Both videos are without IndexedDB.
Video using Hocuspocus provider. Showing problem when you make changes and then reconnect and also showing there is no problem if reconnect happens without changes to document:
https://user-images.githubusercontent.com/9148471/131245789-602d6ea9-545f-488e-a386-f3fdac12bb3a.mp4
Video using Websocket provider. It works just fine even when I make offline changes.
https://user-images.githubusercontent.com/9148471/131245950-f92135ca-3764-404d-864d-bdc40b955f7f.mp4
Environment?
- operating system: Win
- browser: Chrome
- mobile/desktop: desktop @hocuspocus/[email protected] @hocuspocus/[email protected]
Additional context Let me know if you need my code but it is basically Tiptap collab example as I tried to find out if it happens outside of my code
data() {
return {
currentUser: JSON.parse(localStorage.getItem('currentUser')) || {
name: this.getRandomName(),
color: this.getRandomColor(),
},
provider: null,
editor: null,
users: [],
status: 'connecting',
room: 'rooms.9',
ydoc: null,
};
},
mounted() {
const URL = 'wss://websocket.tiptap.dev';
// const URL = 'ws://localhost:8083';
this.ydoc = new Y.Doc();
// console.log('Provider WebsocketProvider');
// this.provider = new WebsocketProvider(URL, this.room, this.ydoc);
// this.provider.on('status', (event) => {
// this.status = event.status;
// });
console.log('Provider HocuspocusProvider');
this.provider = new HocuspocusProvider({
url: URL,
name: this.room,
document: this.ydoc,
onStatus: ({ status }) => {
this.status = status;
},
onSynced: ({ state }) => {
console.log('synced', state);
},
});
this.editor = new Editor({
extensions: [
StarterKit.configure({
history: false,
}),
Highlight,
TaskList,
TaskItem,
Collaboration.configure({
document: this.ydoc,
}),
CollaborationCursor.configure({
provider: this.provider,
user: this.currentUser,
onUpdate: (users) => {
this.users = users;
},
}),
CharacterCount.configure({
limit: 10000,
}),
],
});
localStorage.setItem('currentUser', JSON.stringify(this.currentUser));
},
Thanks for the report! Confirmed, will try to fix it.
I was able to reproduce this back to at least @hocuspocus/[email protected] so far, it's harder for me to go further back than that due to the package incompatibilities, but perhaps that helps debug.
It's this:
https://github.com/ueberdosis/hocuspocus/blob/main/packages/provider/src/HocuspocusProvider.ts#L386-L390
I hacked it back in roughly and everything started working correctly, @hanspagel I'll leave it to you to hook it up with MessageReceiver/MessageSender properly 😆
Confirmed from us too.
How we can reproduce it:
- We don't use onChange, we have observers on the docs that are created in onCreateDocument on the server
- Wait for provider to successfully connect
- Make a change in the client, server observers pick up the edit correctly
- Force a server restart
- Client tries to reconnect, then reconnects successfully
- Make a change in the client, server observers show a wrong state (either an old state, or a new state missing the fields that are being updated), sometimes the observers don't fire at all, the behavior is inconsistent
Confirmed, that’s missing. But I think there is more broken (see related branch issue/183-broken-sync). Not sure if I messed up the whole message handling with my latest refactoring, but I see a lot of things that seem to be wrong. Keep you posted.