I’ve read all the posts you shared, but I still cannot figure out a way to revert changes given a yjs document and a certain snapshot. I understand that to keep using the same document, an update that reverse the changes must be calculated from a snapshot, and transacted to the document.
It doesn’t seem that any of the examples is able to revert an entire document, but only an item in the document.
Kindly can you provide sample code that can do that? In all of the posts you mentioned, there isn’t any official code that is recommended by the y.js team.
However I am unsure if handling doc.gc like this is the correct way when the document might be getting edited at the same time. There is quite limited information documented about “gc”. Is it fine to enable it and disable it as such? Or should this be kind of a permanent setting on the document when it’s first created? Would this ever cause snapshots to break or format to be invalid?
Ah, I understand now. You want a git revert style restoration that updates the doc with a diff back to the snapshot state.
As for the robustness of this technique, it primarily depends on the behavior of UndoManager, which I am not personally familiar with. The technique reaches into the Doc and uses some YJS internals that are not part of its public API, so it may be fragile to YJS upgrades. But for the time being it could work perfectly fine. Perhaps @Himself65 can comment.