Always initialize with the same yjs document if no state is present#5589
Merged
juliusknorr merged 6 commits intomainfrom Apr 2, 2024
Merged
Always initialize with the same yjs document if no state is present#5589juliusknorr merged 6 commits intomainfrom
juliusknorr merged 6 commits intomainfrom
Conversation
b23accd to
5503673
Compare
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Signed-off-by: Julius Härtl <jus@bitgrid.net>
434c3d0 to
9a52473
Compare
Member
Author
|
/backport to stable29 |
mejo-
reviewed
Apr 2, 2024
Member
mejo-
left a comment
There was a problem hiding this comment.
Thanks a lot for diving into this. The explanations seem reasonable to me and sound like a good approach to address the underlying problem.
For now I only have minor comments.
| // to still push a state | ||
| ydoc.clientID = 0 | ||
| const type = /** @type {XmlFragment} */ (ydoc.get('default', XmlFragment)) | ||
| if (!type.doc) { |
Member
Author
There was a problem hiding this comment.
Clarified also with a comment in the code
mejo-
approved these changes
Apr 2, 2024
Member
mejo-
left a comment
There was a problem hiding this comment.
Thanks for the code walkthrough in the call.
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Signed-off-by: Julius Härtl <jus@bitgrid.net>
9a52473 to
ee94449
Compare
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #5574
Fix #4881
When restructuring the y.js state handling we changed the behaviour to only apply the initial content for the first session. Since we no longer cleanup the document state we introduced an issue where a second read only document would no longer show content as the steps the first session tried to push to set the content never appeared (as the read only session cannot push any steps). Apart from this there might still be possible breakage of documents if pushing the steps fails or is not happening for some reason.
I tried to summarize the problems of the current approach in a small diagram:
This is a new approach that fixes the above issue and also cleans up the way we generally initialize the y.js document (which as a side effect also fixes #4881). While this is not the ideal approach from reading up on y.js handling the initial document state, this seems the most reasonable given the technical limitation we have on the backend where we cannot build a y.js document based on the markdown content right now.
With this change we now always initialize a idempotent y.js document state if there is no state file present. This allows us to have the same state accross sessions, which can then pick up syncing their edits immediately and no longer require a step to be pushed and synced from the first to other sessions to have the initial content. On the first save the y.js state is persisted on the server and will be used for any further sessions.
Tests
Some additional cypress tests cover the different scenarios to pick up a document that either starts from the client created initial state or from the server stored one.
Testing concurrent sessions is not that straight forward with cypress, but we could think about recording some edits and replying the API requests while having one tab open showing the changes and asserting the document. However this is left for another time for now.
Additional jest test I used for exploring options, not entirely sure if that is actually useful yet to have in our codebase
Further references