Ghost/ghost/admin/app/controllers
Chris Raible cc88757e2a
Added local revisions to the editor as backstop against data loss (#21044)
ref https://app.incident.io/ghost/incidents/107

- We have a rare bug that causes the initial `POST` request to create a
new post from the editor to be skipped or fail. Subsequent `PUT`
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.
- Since we don't know where the bug is yet, and to protect against
future bugs, we've deliberately avoided depending too heavily on the
`lexical-editor` controller or the ember store. We've aimed to create a
direct route to the state in the editor, by hooking into the
`updateScratch` method (effectively the `onChange` handler for the
editor).
- The `scheduleSave` function on the new `local-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.
- The "schema" of the datastore is a simple key-value store, where the
key is of the format: `post-revision-${postId}-${timestamp}` if the post
has an ID, or `post-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).
- There is currently no UI for viewing/restoring revisions. In the event
that you need to restore a revision, you can access the service in the
browser console. You can access all the saved revisions using the
`list()` method, which logs all the revisions to the console by title &
timestamp. You can then choose a revision to restore, and call
`restore(revision_key)`, which will `POST` the revision's data to the
server to create a new post.
- Since localStorage data is limited to a 5mb quota in most browsers,
the service has a mechanism for evicting the oldest revisions once it
meets the quota. If a save fails because it would exceed the quota, the
`performSave` method will evict the oldest revision, then recursively
try to save again.

---------

Co-authored-by: Steve Larson <9larsons@gmail.com>
2024-09-20 00:08:28 -07:00
..
lexical-editor Lexical-powered editor experiment (#15278) 2022-08-23 11:45:50 +01:00
members Prevented background click closing members import modal (#18296) 2023-09-22 12:01:34 +00:00
posts Wired email debug screen with API (#15919) 2022-12-02 14:38:40 +05:30
activitypub-x.js Added ActivityPub playground (#20081) 2024-04-25 16:44:29 +08:00
application.js Removed cache buster from client extensions script (#20668) 2024-07-25 15:40:12 -07:00
billing.js Refactored billing controller to Octane patterns 2022-10-07 17:59:49 +01:00
collection.js Added collections CRUD UI 2023-05-23 17:26:47 +07:00
collections.js Added collections CRUD UI 2023-05-23 17:26:47 +07:00
dashboard.js Moved onboarding display check into new onboarding service (#19938) 2024-03-27 17:37:37 +00:00
demo-x.js Created a skeleton AdminX demo app (#19005) 2023-11-20 13:30:15 +00:00
designsandbox.js Renamed design sandbox template 2021-02-05 14:00:51 +01:00
error.js Fixed max call stack error on error controller 2022-10-07 19:46:30 +01:00
explore.js Improved URL syncing between Admin and Explore (#15640) 2022-10-21 11:48:18 +01:00
home.js Added display of get-started modal after completing setup flow 2022-02-01 18:20:26 +00:00
lexical-editor.js Added local revisions to the editor as backstop against data loss (#21044) 2024-09-20 00:08:28 -07:00
member.js Revert "🐛 Fixed unexpected leave confirmation after Cmd+S on member profile" 2024-07-02 21:49:08 +02:00
members-activity.js Cleaned up suppressionList feature flag (#16736) 2023-05-04 14:47:04 +02:00
members.js 🐛 Fixed member filtering for "Unsubscribed from newsletter" filters (#20926) 2024-09-16 11:16:49 +02:00
mentions.js Added mentions page for a post 2023-02-22 10:48:15 +01:00
migrate.js Update migration in settings (#19278) 2023-12-13 16:25:29 +01:00
offer.js Fixed ember concurrency cancellation errors (#20324) 2024-06-04 16:20:49 +02:00
offers.js Fixed generating offers in data generator (#19495) 2024-01-16 13:53:34 +00:00
pages-loading.js Refactored posts and pages controllers to Octane patterns 2022-10-07 18:39:34 +01:00
pages.js Improved performance loading posts & pages in admin (#20646) 2024-07-29 16:19:28 +00:00
posts-loading.js Fixed hosting management screen not loading after sign-in process (#15763) 2022-11-03 11:14:36 +00:00
posts.js Improved performance loading posts & pages in admin (#20646) 2024-07-29 16:19:28 +00:00
reset.js Updated password reset notification (#20510) 2024-07-02 15:24:14 +02:00
settings-x.js Fixed bugs with AdminX navigation settings (#17340) 2023-07-13 01:12:31 +00:00
setup.js Fixed browser tests broken by onboarding changes (#19998) 2024-04-08 15:15:04 +01:00
signin.js Updated password reset notification (#20510) 2024-07-02 15:24:14 +02:00
signup.js Fixed hosting management screen not loading after sign-in process (#15763) 2022-11-03 11:14:36 +00:00
site.js [chore] migrate to eslint@8 and run --fix (#2256) 2022-02-10 10:41:36 +00:00
stats.js Stats page refinements (#20924) 2024-09-05 17:49:20 +02:00
tag.js Switched tag unsaved changes modal to new modal pattern 2022-09-09 17:44:11 +01:00
tags.js Refactored tags screens 2022-09-09 13:27:13 +01:00
whatsnew.js Fixed "About Ghost" missing system information 2022-09-13 12:28:21 +01:00