Description
openedon Jun 20, 2018
Describe the bug
If an autosave revision exists for a published post (or draft authored by another user), and non-content field edits exist, isEditedPostAutosaveable
wrongly returns true
, resulting in a 400
bad request response from the autosaves endpoint.
To Reproduce
Steps to reproduce the behavior:
- Navigate to Posts > Add New
- Enter a title
- Publish the post
- Change the title
- Press Preview
- Close Preview tab
- (Ignore fact it may or may not redirect to the preview)
- Reload the page, dismissing the prompt about unsaved changes
- Note there is an "Autosave exists" notice
- Toggle the post as "Stick to the Front Page" in Document settings
- Press preview
Expected behavior
There are no changes to the saved copy of the post to be previewed (title, content, excerpt), so the preview window should direct to the saved post link and not initiate a request to the autosaves endpoint.
Actual behavior
The "Preview Loading" interstitial is wrongly displayed. A request is sent to the autosaves endpoint and responds with a 400 Bad Request code.
Possible solution
The isEditedPostAutosaveable
selector returns early with true
if there is no known autosave:
gutenberg/editor/store/selectors.js
Lines 342 to 345 in 1770317
In the above flow, an autosave exists but it is not known to state. A solution may be to simply ensure that the autosave is populated at the start of the editor session, so it can continue to the condition of the selector which would cause false
to be returned correctly.
Alternatively, we should consider removing the 400 response from the autosaves controller when there are no changes to the autosave, instead treating it as though it were a successful save.
This would arguably be a needless request (a noop), but a preview link could be pulled from its successful response and the user redirected as expected.
Additional context
Part of ongoing struggles with autosave partly addressed in #7130 and relevant Trac ticket.