web-stories-wp
web-stories-wp copied to clipboard
Autosaving while offline (sessionStorage)
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
Current Gutenberg implementation:
https://github.com/WordPress/gutenberg/blob/d694d782feb0bed461efbf390f87b4baaf9b32f9/packages/editor/src/components/local-autosave-monitor/index.js
Technically it's rather simple:
- The content is regularly saved to session storage.
- Whenever a proper autosave to the db happens, session storage is purged
- When loading the editor and there is something different in session storage, a notice is shown to the user

Tested against PR #12129.
- Enabled auto save in Experiments
- Started a new story
- Didn't save changes
- Visited the Dashboard and reopened the story - message was displayed
- Clicked on Dismiss - unsaved changes were not loaded
- Made changes, didn't save them, visited the dashboard and reopened the Story - message was displayed
- Clicked on Restore Backup - changes were loaded
- Made other changes, saved, visited the dashboard and reopened the story - message was not displayed