-
Notifications
You must be signed in to change notification settings - Fork 91
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
fix(sync): push local changes on reconnect #5279
Conversation
0c782e2
to
ad3aa52
Compare
When an editing session is interrupted steps that were already pushed to the server may be cleared alongside the sync service session. Make sure to push all local state that is not part of the document state when (re-)connecting. Tests Yjs relies on a browser environment. Therefore we test it in a cypress test. Move these tests into component tests to separate them from 'normal' e2e tests. Signed-off-by: Max <[email protected]>
Even if all sessions have expired and been removed there may still be disconnected clients that hold state from the last editing session. When they reconnect they will send their yjs updates based on the old state they had. Preserve the yjs state accross editing sessions so updates send after a reconnect can still be processed. Signed-off-by: Max <[email protected]>
ad3aa52
to
fa145e8
Compare
This will break how we currently implemented
We could clear the .yjs file in the cleanup job. We would need to detect this and reload the editor when there is no yjs file during a reconnect. |
That seems reasonable. For a manual test it would be good to try this before/after:
|
@@ -487,6 +487,11 @@ export default { | |||
onLoaded({ documentSource, documentState }) { | |||
if (documentState) { | |||
applyDocumentState(this.$ydoc, documentState, this.$providers[0]) | |||
// distribute additional state that may exist locally |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we always distribute the local (possibly outdated) state? Can we ensure/proof somehow that this does not lead to unexpected reverting of newer changes from the server?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This state is yjs document state. So basically what we are distributing is our local knowledge of the history of the document. yjs will handle sorting those edits and turning them into a current state. In the end it will produce a consistent view for everyone - as long as all are on the same page. We need to share all local history so our future edits will be applied.
Let's say we worked together on a text. I got disconnected but made some changes before the editor noticed. Now I'm reconnecting.
If I distribute my local changes yjs will put all changes in an order and create a current content that may contain my or your changes depending on the order picked by yjs. There's no way of knowing what would be the correct order and we would have to live with that. At least we have a consistent view on the content.
If I keep connect without distributing my local changes I will receive your changes - the doc would probably look the same as above for me. Your view would stay the same as it was when i was disconnected and changes i make later on will not show for you.
If I drop all local changes and basically reload the editor we'd also be on the same page and my changes would be lost.
a80a79f
to
bf5d7f8
Compare
Signed-off-by: Max <[email protected]>
bf5d7f8
to
a643da0
Compare
Signed-off-by: Max <[email protected]>
Signed-off-by: Max <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for looking into this ❤️
I tried to follow the logic of the code and your changes seem reasonable to me - also taking into account yours and Julius' comments. I didn't test myself and would give yours and Julius' assessment more weight than mine since I struggle to keep the big picture about yjs and document state in my head 🤯
BeforeSomewhat mixed results:
None of this seems so good that we would want to keep it ;). After
So this seems fine. |
Remove duplicate encoding for updateMessage Signed-off-by: Max <[email protected]>
Sorry, I've had probably some confusion when testing yesterday. Did a reset now (probably with a bit more concentration) and it seems to work well. I couldn't see any trouble with changes being reverted. |
As the e2e test checkbox is still unchecked, any idea how you could test that? But would not consider that a blocker for the merge |
/backport to stable28 |
/backport to stable27 |
/backport to stable26 |
When an editing session is interrupted
steps that were already pushed to the server
may be cleared alongside the sync service session.
Make sure to push all local state
that is not part of the document state
when (re-)connecting.
Todo
y-protocols
to package.json.yjs
file on server side even during session cleanup🏁 Checklist
npm run lint
/npm run stylelint
/composer run cs:check
)