Don't error if autosave runs and there are no changes to save#7347
Don't error if autosave runs and there are no changes to save#7347notnownikki merged 2 commits intomasterfrom
Conversation
| if ( ! $autosave_is_different ) { | ||
| wp_delete_post_revision( $old_autosave->ID ); | ||
| return new WP_Error( 'rest_autosave_no_changes', __( 'There is nothing to save. The autosave and the post content are the same.', 'gutenberg' ) ); | ||
| return new WP_Error( 'rest_autosave_no_changes', __( 'There is nothing to save. The autosave and the post content are the same.', 'gutenberg' ), array( 'status' => 200 ) ); |
There was a problem hiding this comment.
I think 400 is more appropriate here than 200. We should return 400 from the REST API, and then have special handling in Gutenberg for a 400 from the autosaves endpoint.
There was a problem hiding this comment.
I've changed this to 400, and handled this specific error in the REQUEST_POST_UPDATE_FAILURE effect.
aduth
left a comment
There was a problem hiding this comment.
If autosave runs and there are no changes, the user gets an error banner.
Ideally, we should never be sending an autosave request in the first place if there are no changes to be saved. As currently implemented, I could imagine there may be cases where the user makes a change and manually resets it back to the original value where autosave could happen (particularly for post content). And regardless it does seem reasonable we don't want to surface/alarm the user on this type of error.
Would this apply for any autosave error (i.e. never show warnings on failed autosave)? I'd guess depending on the error type, we would want to show a notice, so fine as-is.
| const { post, edits } = action; | ||
| const { post, edits, error } = action; | ||
|
|
||
| if ( error && 'rest_autosave_no_changes' === error.code ) { |
There was a problem hiding this comment.
In what situations will we expect error to be empty such that we'd want to check its truthiness? If it's expected, we should have a separate unit test for this circumstance as well.
There was a problem hiding this comment.
I'm not sure here. While REQUEST_POST_UPDATE does include the error in the dispatched action, REQUEST_POST_UPDATE_FAILURE didn't use it until this change, and several tests didn't include an error either, so I felt it was safer to include this check until someone who knows things better could say for certain if the error would always be there or not.
Description
If autosave runs and there are no changes, the user gets an error banner. This happens when there's an autosave newer than the post content you're editing, and autosave runs again.
This change sets the status code of the error to 200, because the fact that there are no changes since the last autosave shouldn't be an error we alert users to.
Types of changes
Bug fix