Skip to content
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

Saving: Post with only "Classic" block fails to autosave #7727

Closed
aduth opened this issue Jul 5, 2018 · 3 comments
Closed

Saving: Post with only "Classic" block fails to autosave #7727

aduth opened this issue Jul 5, 2018 · 3 comments
Labels
[Feature] Saving Related to saving functionality [Type] Bug An existing feature does not function as intended

Comments

@aduth
Copy link
Member

aduth commented Jul 5, 2018

When a post only contains a "Classic" block, it attempts to autosave but fails.

image

Steps to reproduce:

  1. Navigate to Posts > Add New
  2. Insert a "Classic" block
  3. Wait a few seconds
  4. Autosave kicks in, then fails with notice

Suspected cause:

There is special handling for the classic block to omit its comment demarcation wrapper, so while the editor knows that a block exists and thus thinks the post is saveable, when it's the only content, it will be serialized as the empty string, which is not valid for save.

export function serializeBlock( block ) {
const blockName = block.name;
const blockType = getBlockType( blockName );
const saveContent = getBlockContent( block );
const saveAttributes = getCommentAttributes( block.attributes, blockType );
switch ( blockName ) {
case getUnknownTypeHandlerName():
return saveContent;
default:
return getCommentDelimitedContent( blockName, saveAttributes, saveContent );
}
}

/**
* Returns true if the edited post has content. A post has content if it has at
* least one block or otherwise has a non-empty content property assigned.
*
* @param {Object} state Global application state.
*
* @return {boolean} Whether post has content.
*/
export function isEditedPostEmpty( state ) {
return (
! getBlockCount( state ) &&
! getEditedPostAttribute( state, 'content' )
);
}

It is not a safe assumption to imply that the presence of blocks means that content is non-empty. isEditedPostEmpty should at least be updated to account for this special Classic block behavior.

@aduth aduth added [Type] Bug An existing feature does not function as intended [Feature] Saving Related to saving functionality labels Jul 5, 2018
@danielbachhuber
Copy link
Member

Duplicate of #6556 (comment)

@olygoelements
Copy link

i have the same error.
gutenberg have a conflict
i have upgrade php 7.1 to 7.2
and now is work

@aduth
Copy link
Member Author

aduth commented Sep 12, 2018

@olygoelements The "Updating failed" message is a pretty common error that applies broadly to issues where the request to save the post via the REST API fails for some reason. I expect your issue may not be quite the same as what was described here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Saving Related to saving functionality [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

3 participants