Best way to replay steps

I’m working on an offline storage story for our project. We’d like to handle intermittent connection losses gracefully.

We’re set up with the collab plugin. The idea is to locally cache changes made to the document while the disconnected from the authority, and re-apply them upon reconnection. One trick has been how to handle the case where the authority version number has incremented before a given client comes back online again with changes. Seems we should replay those changes through the editor state somehow, but I don’t see an easy way to create transactions from steps, and serializing de-serializing transactions to and from JSON is non trivial.

Any advice? Helpful tips?


In principle, this should just work — the collab plugin already keeps track of which changes are new since it last synced with the authority, and will rebase those on top of any new changes it receives when it comes back online, before sending them to the authority. For momentary connection losses, or when not a lot happens on one side, this should be enough.

If you are offline for a while, and both you and other people make a lot of changes, the non-interactive merge that rebasing does might cause data loss, though (if you wrote stuff in a place that someone else deleted, it’ll be gone). There isn’t an out-of-the-box solution for that case yet, but it’d probably look like showing the changes side-by-side when they overlap and letting the use manually merge somehow.

Great - thanks Marijn!

@mtejera You may want to look at the package I created [1] that attempts to recreate lost step information and merge conflicting changes to the same document (it can be setup up to automerge everything that can be merged without conflicts and show a A-or-B interface for those changes where one has to choose between A or B. Merging changes is no exact science, and contributions are very welcome.

[1] Recreating steps