web-stories-wp
web-stories-wp copied to clipboard
Autosaves: local `auto-draft` autosave not cleared after proper save
Bug Description
After admin user deletes and re-installs the plugin, if a new story is added, the end user gets the "Restore from Backup" dialogue. Clicking the restore button brings an older version of the last story that was saved from the previous version of the plugin.
Expected Behaviour
As an end user, when the plugin is deleted, there is a message that says all data will be deleted.
After the re-install, when user adds a new story, it is confusing if they are given the option to restore. And even then, the restored version is not the immediately previous version.
Steps to Reproduce
- Add a new story, save it as draft.
- Add an extra page and make some edits but DO NOT SAVE
- After about a minute, exit the story editor and open the draft story again
- Restore Back up appears, and clicking restore shows the extra page that was added in step 2. This is expected Restore Backup workflow
- Now disable and delete the plugin
- Next reinstall the plugin and go to add a new story
- You are given the Restore from backup option
- Clicking restore gives you the draft version from step 1. The edits in step 2 above are not restored.
Screenshots
Additional Context
- Plugin Version: v1.25-rc3
- WordPress Version: Wp 6.0.2
- Operating System: Win10
- Browser: Edge
This basically boils down to:
- Create new story
- Wait for local autosave ->
wp_stories_autosave_story_auto-draft
gets created - Make proper save
- Make more changes
- Wait for local autosave ->
wp_stories_autosave_story_12345
gets created - Notice that
wp_stories_autosave_story_auto-draft
is not discarded at this point
Because of (6), the next time you create a new story you'll get the backup warning.
So what we need to do is purge the auto-draft autosave after a proper save occurs.
See how Gutenberg does this here:
https://github.com/WordPress/gutenberg/blob/799a3e93c221542c1376f9ec114c8762457db8ef/packages/editor/src/components/local-autosave-monitor/index.js#L129-L169
Related: #12343