fix(setInitialYjsState): do not push or save the initial state on open - #9103
fix(setInitialYjsState): do not push or save the initial state on open#9103silverkszlo wants to merge 1 commit into
Conversation
Opening a document without a stored yjs state applied the generated initial state as a local update. It was then pushed to the server like a user edit, which marked the document dirty and triggered an autosave, even for a freshly created and untouched document. Apply the initial state with the sync provider as origin so it counts as received from the server. The provider sends diffs against the known server state, so the first real user edit still carries the initial state along with it. Signed-off-by: silver <s.szmajduch@posteo.de> Assisted-by: ClaudeCode:claude-fable-5
Background / history of the codeThere's a bit of history to the code in question. We used to have an issue where opening a |
This changeThis change avoids pushing the initial step - that is the step that loading the initial document creates - to the server. In theory every client will create that step on its own based on the file content. We made the step deterministic on purpose so it could be generated based on the file content and then still be applied when received from the server. I'm not sure if we are currently generating the step when already receiving steps from the server. But that could be adjusted. In my mind the full set of steps thus far always was enough to sync the y doc to the latest. This would not be the case anymore if we merge this PR. In addition to the steps we'd always rely on the initial markdown content. The initial markdown content will be overwritten with the first autosave. At the same time this autosave also pushes the document state which includes the initial step - so the content is not needed anymore. So far the document state is a compressed form of all the steps leading up to it. So in a way it is redundant. This change would make it so it's not redundant anymore as the initial content would be overwritten and only stored in the document state. I can't think of any breakages as consequences of this change but I'd argue that this makes the overall system less robust against race conditions. |
AlternativesI'd prefer a change that does not change the data flow between the server and client but only the initial autosave behavior. Two possibilities come to my mind:
I don't like either of the two as they both involve coupling the One variant that would decouple the
|


馃摑 Summary
Opening a document without a stored yjs state applied the generated initial state as a local update. It was then pushed to the server like a user edit, which marked the document dirty and triggered an autosave, even for a freshly created and untouched document.
Apply the initial state with the sync provider as origin so it counts as received from the server. The provider sends diffs against the known server state, so the first real user edit still carries the initial state along with it.
馃弫 Checklist
npm run lint/npm run stylelint/composer run cs:check)馃 AI (if applicable)