-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -118,12 +118,23 @@ export default { | |||
|
|||
let request; | |||
if ( isAutosave ) { | |||
toSend.parent = post.id; | |||
const autosaveData = {}; |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
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.
LGTM 👍
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: