-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent content loss after refreshing an editor with unsaved auto-draft post #23928
Conversation
…Clear to make them work with brand new unsaved posts
Size Change: -1.02 MB (88%) 🏆 Total Size: 1.15 MB
ℹ️ View Unchanged
|
It's worth noting that after applying this PR, saving the post will change the current autosave key from something like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
if ( prevPostId === postId && wasEditedPostNew && ! isEditedPostNew ) { | ||
localAutosaveClear( postId, true ); | ||
} | ||
}, [ isEditedPostNew, postId ] ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be moved to useAutosavePurge
instead? Seems like this hooks is meant to be used for these things?
Description
See #23781
The autosave stores the content in
window.sessionStorage
under 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-draft
autosave 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: