Implement time travel (undo/redo/revert) of auto-saved states across devices and users

Created on 16 October 2024, 2 months ago

Overview

Currently, XB maintains an undo stack via Redux, but it's local to the user and the device the user is on. Currently it doesn't even survive a browser page refresh, but in principle it could be changed to use the browser's localStorage, but that would still be limited to the device.

In 🌱 Research: Possible backend implementations of auto-save, drafts, and publishing Active , we're working out the requirements and design for auto-saving to the server, similar to Google Docs and other modern apps where users don't have to think about clicking a Save button.

In #3475672-49: Research: Possible backend implementations of auto-save, drafts, and publishing β†’ , @lauriii wrote that "It should be possible to revert back to previous revisions and auto-save states.".

Drupal already supports reverting to previous revisions, but being able to revert to previous auto-saved server-stored states is tricky, so this is a spin-off issue for just that piece.

Efficiently storing and time traveling through an entire history of small incremental edits within a document is a problem space that collaborative-editing tools/frameworks/libraries have put a lot of work into. I think that that plus the fact that we want XB to eventually support collaborative editing should point us to using one of those libraries for implementing time travel through auto-saved states, even if we don't need the collaborative editing part of it just yet. However, a challenge is that those libraries are written in JavaScript (or something that JavaScript can call via WASM) rather than in PHP. So if we need to support Drupal's server-side code to be able to query/inspect/validate anything about an auto-saved document's history, then we'll need to figure out how to integrate one of those libraries in a way that allows that.

Proposed resolution

Some collaborative-editing libraries (that also maintain a complete editing history) to look into:

We'll need to investigate if any of these libraries (or some other one) provides a document format that Drupal's PHP code could interact with directly (not via the library) enough to serve the product features that require server-side code. Hopefully, all of the hard stuff could be done by XB's JS code, which would be able to use the library's API rather than needing to interact with the document format directly.

User interface changes

✨ Feature request
Status

Active

Version

0.0

Component

Data model

Created by

πŸ‡ΊπŸ‡ΈUnited States effulgentsia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @effulgentsia
  • πŸ‡ΊπŸ‡ΈUnited States effulgentsia
  • πŸ‡ΊπŸ‡ΈUnited States effulgentsia
  • πŸ‡¬πŸ‡§United Kingdom catch

    Another thing to add here is that if we do decide to implicitly save a revision every so often when an autosave state is valid/ready to save, then it would be possible to revert to those interim revisions instead of the auto-save state itself. This does not help with a full collaborative editing workflow but might be an interim step in lieu of one which would avoid having to revert to actual autosave states as such.

  • πŸ‡ΊπŸ‡ΈUnited States effulgentsia

    Re #4, if we want to pursue an interim solution where we either retain a partial history of auto-saved non-revisions, or a partial history of auto-saved actual-revisions, I'd recommend we do it as logarithmically-spaced snapshots. That way, even if the content author makes 1000 autosaved edits prior to sending their work into a "for review" state, we'd only need to save/retain 10 or so states/revisions, which actually seems quite manageable even without any of the libraries proposed in this issue. https://madebyevan.com/algos/log-spaced-snapshots/ has a clever algorithm for how to do this in a way that only requires at most one deletion per save. That post shows an example with a "density" of 2, but we might find that even a density of 1 is sufficient.

Production build 0.71.5 2024