web-stories-wp icon indicating copy to clipboard operation
web-stories-wp copied to clipboard

Autosaving while offline (sessionStorage)

Open swissspidy opened this issue 4 years ago • 2 comments

Feature Description

When the user is editing a story while being offline, can we store autosaves in sessionStorage like Gutenberg does?

Then we could display messages like "The backup of this post in your browser is different from the version below. Restore backup"

Alternatives Considered

Additional Context

Related: #3841 (Add message when Autosave exists)

Original Gutenberg implementation: https://github.com/WordPress/gutenberg/pull/16490

Code is currently here: https://github.com/WordPress/gutenberg/blob/7d880708c6281c185256b8e7d3dffe178da33d09/packages/editor/src/components/local-autosave-monitor/README.md


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance Criteria

Implementation Brief

swissspidy avatar Aug 12 '20 17:08 swissspidy

Current Gutenberg implementation:

https://github.com/WordPress/gutenberg/blob/d694d782feb0bed461efbf390f87b4baaf9b32f9/packages/editor/src/components/local-autosave-monitor/index.js

Technically it's rather simple:

  1. The content is regularly saved to session storage.
  2. Whenever a proper autosave to the db happens, session storage is purged
  3. When loading the editor and there is something different in session storage, a notice is shown to the user

swissspidy avatar Dec 07 '21 23:12 swissspidy

![Screenshot 2021-12-07 at 22 11 23](https://user-images.githubusercontent.com/841956/145122381-e2d3ded8-b3f1-499d-b538-8134c6844697.png Screenshot 2021-12-07 at 22 11 55 Screenshot 2021-12-07 at 22 11 32 )

swissspidy avatar Dec 07 '21 23:12 swissspidy

Tested against PR #12129.

  1. Enabled auto save in Experiments
  2. Started a new story
  3. Didn't save changes
  4. Visited the Dashboard and reopened the story - message was displayed
  5. Clicked on Dismiss - unsaved changes were not loaded
  6. Made changes, didn't save them, visited the dashboard and reopened the Story - message was displayed
  7. Clicked on Restore Backup - changes were loaded
  8. Made other changes, saved, visited the dashboard and reopened the story - message was not displayed

popup.png

felipebochehin87 avatar Aug 22 '22 16:08 felipebochehin87