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

Autosaves: local `auto-draft` autosave not cleared after proper save

Open kkalarickal opened this issue 2 years ago • 2 comments

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

  1. Add a new story, save it as draft.
  2. Add an extra page and make some edits but DO NOT SAVE
  3. After about a minute, exit the story editor and open the draft story again
  4. Restore Back up appears, and clicking restore shows the extra page that was added in step 2. This is expected Restore Backup workflow
  5. Now disable and delete the pluginimage.png
  6. Next reinstall the plugin and go to add a new story
  7. You are given the Restore from backup optionimage.png
  8. 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

kkalarickal avatar Sep 20 '22 12:09 kkalarickal

This basically boils down to:

  1. Create new story
  2. Wait for local autosave -> wp_stories_autosave_story_auto-draft gets created
  3. Make proper save
  4. Make more changes
  5. Wait for local autosave -> wp_stories_autosave_story_12345 gets created
  6. 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

swissspidy avatar Sep 20 '22 13:09 swissspidy

Related: #12343

swissspidy avatar Sep 20 '22 13:09 swissspidy