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 3 commits into
Conversation
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
|
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
Signed-off-by: silver <s.szmajduch@posteo.de> Assisted-by: ClaudeCode:claude-sonnet-5
Opening a document without a stored yjs state applies a generated initial state to the ydoc. That push still needs to reach the server and be recorded as a normal step, so recovery and later clients can rely on the full step history. But it should not, on its own, trigger an autosave of a document the has not edited yet. Arm a one-shot skip on SaveService before generating the initial state, consumed by the very next changesPushed-triggered autosave attempt. Signed-off-by: silver <s.szmajduch@posteo.de> Assisted-by: ClaudeCode:claude-sonnet-5
8e5b6dd to
44233fa
Compare


馃摑 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)