Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Editor: Add sessionStorage autosave mechanism #16490
Some edits by @mcsf
This pull request seeks to implement periodic
This influenced the choice to not use the existing data persistence behavior, along with a desire to avoid creating saves until the interval has elapsed (vs. on every state change).
Even with the delay, we may want to explore using
The autosaves occur every 15 seconds after the last change has occurred. Verify that upon waiting this duration and reloading the page (dismissing the prompt), you see a restore option to restore the title, content, and excerpt of the post you had been working on.
Verify that the prompt is not shown if you proceed to make edits to the post and save (regardless of whether you choose to restore or dismiss the notice).
Checklist: (Added 2019-08-30)
Using serve workers would be a supplement, especially because they require HTTPS. In #6322 @westonruter actually shared some very good ideas on how they could enhance the editing experience when offline.
For example, it can cache assets and even REST API responses locally. So when you are offline, you could still refresh the page, select tags, and write content as usual. You could even go and edit some totally different post and have all the (cached) data at your fingertips. And thanks to background sync, any attempt to save the post will be recorded and run as soon as you get online again.
While https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API covers the fundamental basics of service workers, I recommend checking out the PWA feature plugin as it includes some of these things I mentioned already, just for other parts of WordPress. For example, it has background sync for comments and support for a dedicated offline template that is shown when there's no cached content.
This probably won't matter so much, but I wanted to mention:
Thanks all for the feedback!
A few specific action items I've observed:
As Andrew is enjoying some time off, I've revived this branch and applied some of the feedback that's been provided. A couple of notes:
I don't think this is something to address in this PR, but it's something to be aware of.
JSON.stringify would not include properties with undefined values, so it is not necessary to omit them explicitly
Keys are crucially prefixed with 'wp-autosave-' so that wp-login.php's `loggedout` handler can clear sessionStorage of any user-private content. See: https://github.com/WordPress/wordpress-develop/blob/6dad32d2aed47e6c0cf2aee8410645f6d7aba6bd/src/wp-login.php#L103
gziolo left a comment
This works great, let's move forward with it once we add back deprecated message for the removed selector with the proper warning printed to the console. See: #16490 (comment)
As a follow-up tasks we should do the following:
A performance benchmark:
local autosave, no editor setting
local autosave, with editor setting