-
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
Add end 2 end test: should not revert title during a preview right after a save draft #7953
Add end 2 end test: should not revert title during a preview right after a save draft #7953
Conversation
0202a14
to
c35fa8c
Compare
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.
This seems like something going wrong with how we're trying to fall back to post values in creating the autosave payload:
gutenberg/packages/editor/src/store/effects/posts.js
Lines 107 to 114 in 25f364b
// Ensure autosaves contain all expected fields, using autosave or | |
// post values as fallback if not otherwise included in edits. | |
toSend = { | |
...pick( post, [ 'title', 'content', 'excerpt' ] ), | |
...getAutosave( state ), | |
...toSend, | |
parent: post.id, | |
}; |
Why is it that without the proposed change, title
is not set the edited value?
It's also not entirely sensible that we're even calling the autosave endpoint in the first place, since we've just saved the post and there's nothing to be autosaved.
Finally, we should consider excerpt as well, since an autosave is of its title, content, and excerpt. Following the original instructions, but using excerpt instead of the title, the misbehavior still exists.
You might need to update your theme to make this apparent. I included <?php the_excerpt(); ?>
in my theme's single.php
for example.
Is there any way we can include a test for this?
Are you able to resume work here? |
Sure @aduth I'm sorry for the delay I totally missed your comment in the middle of other notifications. Edited: I think I already understand the problem, I'm working in updating this PR. |
6fc2105
to
5c19314
Compare
Hi @aduth thank you for the insights, I updated this PR to use another fix. Now on the preview, we have a new condition that makes sure the autosave is not triggered if the post is not dirty. That may have been the original intention as the isDirty flag was being retrieved from the state but not used anywhere on the component. |
5c19314
to
e3598ce
Compare
End 2 End tests are executing with success, I think it was some problem in Travis that made them fail. I executed them and they are passing. I added a new test case for this bug (that fails on master). |
e3598ce
to
421bf10
Compare
isNew: isEditedPostNew(), | ||
isSaveable: isEditedPostSaveable(), | ||
isAutosaveable: isEditedPostAutosaveable(), | ||
isAutosaveable: isEditedPostAutosaveable() && isEditedPostDirty(), |
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.
Should isEditedPostAutosaveable
encompass isEditedPostDirty
?
7b86a0f
to
0fd7fb7
Compare
if ( ! isEditedPostSaveable( state ) ) { | ||
// A post needs to be in dirty state and, | ||
// a post must contain a title, an excerpt, or non-empty content to be valid for autosaving. | ||
if ( ! isEditedPostDirty( state ) || ! isEditedPostSaveable( state ) ) { |
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.
I noticed this comment previously about why isEditedPostDirty
can't be used in isEditedPostSaveable
and wondered whether it applies here as well:
gutenberg/packages/editor/src/store/selectors.js
Lines 346 to 349 in 1349d23
// TODO: Post should not be saveable if not dirty. Cannot be added here at | |
// this time since posts where meta boxes are present can be saved even if | |
// the post is not dirty. Currently this restriction is imposed at UI, but | |
// should be moved here. |
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.
I don't think so, as my expectation is that meta boxes don't trigger autosaves. I think what happens is that isDirty does not account for meta boxes, so if meta boxes are present the save button is always available.
I'm a bit unclear on why previous autosave data is even included in the payload for a new autosave: gutenberg/packages/editor/src/store/effects/posts.js Lines 110 to 115 in 5c19314
Wouldn't just |
Hi @talldan,
I did not have knowledge about how autosaving works but I did some digging, and it looks like autosave payloads always need to include the three fields as specified in the comments 'title', 'content', 'excerpt'. When for example title is updated, and an autosave happens, if after we change content, toSend does not contain the title, and the post includes the title before the autosave so for us to send the most recent title in a second autosave we need retrieve the title from the previous autosave. |
4f7e103
to
15178ae
Compare
This PR passed by a rebase, and some code changes were applied. In summary, this PR just adds a rule, "A post non dirty post is not autosaveable", the other changes are test cases and removing of isDirty check when it is already included in the autosave check. |
I think the required improvements were applied.
@jorgefilipecosta In trying to reproduce the original issue in master, I'm finding it to be working as intended. Can you verify whether the bug is still present? I'm thinking it may have been incidentally resolved by @youknowriad 's #12097 . |
15178ae
to
31c1a11
Compare
Hi @aduth that you for retesting this. You are right the issue was solved, I confirmed in manual tests and the end 2 end test also confirms it. |
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.
Looks good 👍
Description
Adds an end 2 end test that verifies the we don't regress on issue #7927.
The test does the following:
Adds a post.
Writes aaaa in title and clicks save draft.
Presses preview.
See the title is correctly previewed as aaaa.
Goes back to the editor ands appends bbbb to the title, presses save draft. Presses preview right after the post is saved.
Verify that on the preview of the post we see 'aaaabbbb' as the title of the post.
How has this been tested?
Verify end 2 end tests run with success.