Repository navigation
fix(sync): do not push or save the generated initial state on open - #9589
Conversation
blizzz
left a comment
There was a problem hiding this comment.
With a by-catch might be worth a follow up, as it was not introduced (though affected) here: typing after a document reset is silently lost
- Create
a.mdwith at least two versions. Delete its Text document state, for example withocc text:reset --full <fileId>. - User A opens
a.mdwith one editor only, which means a 5 s poll interval, or 20 s if the tab is hidden. A does not type. - User B restores an older version in the Versions sidebar.
- Before A's next poll, A types "LOST".
- The push returns 412, an "Editing session has expired" toast appears and the page reloads.
- "LOST" is gone.
localStorage['text-indexeddb-conflict-file-<id>']is not set.
- Control: on
main, step 3 leaves the document untouched.hasUnsavedChangesis true because of the initial step, so the restore does not reset it.
Opening a file without a stored Yjs state applied the state generated from the markdown as a local change. It was pushed like an edit, which marked the document dirty, so closing the viewer or leaving the page saved the re-serialized markdown even though nothing was edited. This dropped trailing newlines and normalized the syntax of untouched files. Apply the initial state with the sync provider as origin. Every client generates the same state from the file content, and the provider sends it along with the first local change, as it sends everything the server does not have yet. Fixes: #9077 Signed-off-by: Jonas <jonas@freesources.org> Assisted-by: ClaudeCode:claude-opus-5-5
Only versions that were pushed but not saved yet marked the document as dirty. Changes made while offline were therefore not marked dirty: they were not kept in IndexedDB for recovery, and no conflict resolution was offered when the file changed meanwhile. Track whether the outbox holds a local update that was not pushed yet and include it in the dirty state. Push pending changes before saving, so the save includes them, and autosave versions that were pushed by a retry without an editor update. Signed-off-by: Jonas <jonas@freesources.org> Assisted-by: ClaudeCode:claude-opus-5-5
f3308c0 to
ea24645
Compare
|
I assumed I had fixed this in 6be8cd3 Did not know about the linked issue - so I did not test it. Will check if this can still be reproduced. |
|
Ah... I see. This is about the dirty tracking not autosave. |
max-nextcloud
left a comment
There was a problem hiding this comment.
First commit makes sense to me either way.
Second commit I would prefer to set the dirty state on updates that are added to history just like we trigger the autosave. That would make sure the two behave consistently and seems simpler from my point of view.
That way, Undo/Redo wouldn't trigger a push/save request after going online again as they're I'm too tired now to put it into my own words, so I'll let claudes findings here:
Text uses the undo/redo from Yjs (via tiptap's Collaboration extension). An undo changes the Yjs document, and y-prosemirror then applies that change to the editor with addToHistory: false (node_modules/y-prosemirror/src/plugins/sync-plugin.js:355, used at :635). So autosaveOnUpdate ignores undo and redo, and a dirty flag based on the same check would too. I tested this with a scratch spec on nextcloud.local:
With Max's approach, the second row stays as on main. An undo made offline is never marked dirty, so there's no IndexedDB recovery and no conflict dialog. Your second commit gets the first row right as a side effect: once the undo is pushed, the new autosave on unsaved pushed versions picks it up.
The flag would also need to be reset at some point.
The outbox is where "this local change hasn't reached the server" is actually known, so dirty follows it exactly.
On reopen, sendUpdateFromDoc('offline', …) sends the changes recovered from IndexedDB directly to the provider. That isn't an editor transaction at all. The outbox sees these changes, while an editor listener would not. On consistency Your second commit already brings autosave closer to dirty. Any change that reaches the server unsaved now gets autosaved, whatever caused it, and that includes undo and retried pushes. Making dirty as narrow as the autosave trigger would bring the two back in line by reintroducing these gaps. |
|
/backport to stable35 |
Opening a file without a stored Yjs state applied the state generated from the markdown as a local change. It was pushed like an edit, which marked the document dirty, so closing the viewer or leaving the page saved the re-serialized markdown even though nothing was edited. This dropped trailing newlines and normalized the syntax of untouched files.
Apply the initial state with the sync provider as origin. Every client generates the same state from the file content, and the provider sends it along with the first local change, as it sends everything the server does not have yet.
Fixes: #9077
Assisted-by: ClaudeCode:claude-opus-5-5
🏁 Checklist
npm run lint/npm run stylelint/composer run cs:check)🤖 AI (if applicable)