-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added local revisions to the editor as backstop against data loss #21044
Draft
cmraible
wants to merge
16
commits into
main
Choose a base branch
from
editor-local-revisions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+524
−1
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This reverts commit c87d4bf.
cmraible
changed the title
🚧 Added initial API of local revisions service with in-memory store
🚧 Added local revisions to the editor
Sep 19, 2024
cmraible
changed the title
🚧 Added local revisions to the editor
🚧 Added local revisions to the editor as backstop against data loss
Sep 19, 2024
…ing for localstorage
cmraible
changed the title
🚧 Added local revisions to the editor as backstop against data loss
Added local revisions to the editor as backstop against data loss
Sep 20, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
ref https://app.incident.io/ghost/incidents/107
POST
request to create a new post from the editor to be skipped or fail. SubsequentPUT
requests then fail because there is no post ID, potentially resulting in data loss. The aim of this commit is to start saving revisions of posts in the editor to the browser's localStorage, as a last-ditch option to restore lost work.lexical-editor
controller or the ember store. We've aimed to create a direct route to the state in the editor, by hooking into theupdateScratch
method (effectively theonChange
handler for the editor).scheduleSave
function on the newlocal-revisions
service is called immediately upon any changes to the state of the lexical editor, which is effectively every keystroke. The service has some logic and timeouts, so it doesn't actually save a revision on every change to the editor.post-revision-${postId}-${timestamp}
if the post has an ID, orpost-revision-draft-${timestamp}
for an unsaved draft. There is also an array of all the revisions' keys, which allows us to clear all the revisions without having to loop over every key in localStorage (along with some other conveniences, like filtering).list()
method, which logs all the revisions to the console by title & timestamp. You can then choose a revision to restore, and callrestore(revision_key)
, which willPOST
the revision's data to the server to create a new post.performSave
method will evict the oldest revision, then recursively try to save again.