Send all fields when transmitting an autosave.#7092
Conversation
editor/store/effects.js
Outdated
| Object.assign( autosaveData, | ||
| { | ||
| title: post.title, | ||
| content: post.content, |
There was a problem hiding this comment.
Unlike title and excerpt, toSend will always have an assigned value for content, and thus will always override. This line will never take effect.
There was a problem hiding this comment.
Also wondering: Since isEditedPostAutosaveable uses property values from state.autosave to consider a field as having been changed, should we be using those here as well as the original value to fall back to? Maybe with a getCurrentAutosave selector?
toSend = {
...getCurrentAutosave(),
...toSend,
parent: post.id
};
editor/store/effects.js
Outdated
| let request; | ||
| if ( isAutosave ) { | ||
| toSend.parent = post.id; | ||
| const autosaveData = {}; |
There was a problem hiding this comment.
Minor: If we use let instead of const to declare toSend, with spread syntax we could simplify this a bit:
toSend = {
title: post.title,
excerpt: post.excerpt,
...toSend,
parent: post.id
};There was a problem hiding this comment.
And if we want to take it a step further with Lodash's _.pick:
toSend = {
...pick( post, [ 'title', 'excerpt' ] ),
...toSend,
parent: post.id
};|
@adamsilverstein I just pushed d10a64e which accounts for all of my feedback. The request body accounts for both the fields from the current post, but preferring values from Otherwise there may be some edge cases where e.g. post is autosaved ( I don't know that that needs to be addressed as part of this pull request specifically. |
Description
merges the post object with toSend before sending the autosave, ensuring that unedited fields are sent with their current values.
Fixes #7078
How has this been tested?
Create a post and publish it.
Change the content of the post and wait 10 seconds for the autosave to fire.
Check the autosave REST request - note that the title is present in the request. Check the database and note the autosave title is present in the database.
Changes
I found that altering the original object sets up an infinite save loop, to avoid this I create a new object to send to autosaves and leave toSend untouched.
Checklist: