Prevent content loss after refreshing an editor with unsaved auto-draft post#23928
Merged
Conversation
…Clear to make them work with brand new unsaved posts
|
Size Change: -1.02 MB (88%) 🏆 Total Size: 1.15 MB
ℹ️ View Unchanged
|
Contributor
Author
|
It's worth noting that after applying this PR, saving the post will change the current autosave key from something like |
This was referenced Jul 14, 2020
draganescu
approved these changes
Jul 16, 2020
draganescu
left a comment
Contributor
There was a problem hiding this comment.
Tested locally as described and it worked. After editing with a down server, starting the server and refreshing I was able to restore my backup.
youknowriad
reviewed
Jul 16, 2020
| if ( prevPostId === postId && wasEditedPostNew && ! isEditedPostNew ) { | ||
| localAutosaveClear( postId, true ); | ||
| } | ||
| }, [ isEditedPostNew, postId ] ); |
Contributor
There was a problem hiding this comment.
Should this be moved to useAutosavePurge instead? Seems like this hooks is meant to be used for these things?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
See #23781
The autosave stores the content in
window.sessionStorageunder the ID of the currently edited post. When the page is refreshed, WordPress creates a new auto-draft post, which means there's a new ID, which means that after refreshing the page the autosave code looks for a backup under a different cache key. For a user it seems like all my previous content is gone forever:This PR adds an
auto-draftautosave key to backup the content of new posts.How has this been tested?
What I managed to reproduce:
wp-env stop.Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist: