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

Try fixing Heading block validation errors on native #16195

Closed
wants to merge 1 commit into from

Conversation

Tug
Copy link
Contributor

@Tug Tug commented Jun 17, 2019

Description

This is a WIP. I'm trying to fix the block validation errors we're seeing on Gutenberg RN. Also experimenting with (auto?-)migration

Block validation: Block validation failed for `core/heading` ({name: "core/heading", save: ƒ, category: "common", attributes: {…}, title: "Heading", …}).

Content generated by `save` function:

<h2 class="has-text-align-left">Meet your new best friends, Blocks</h2>

Content retrieved from post body:

<h2 style="text-align:left">Meet your new best friends, Blocks</h2>

How has this been tested?

TBD

Types of changes

React Native

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.

@Tug Tug added the Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change) label Jun 17, 2019
@Tug Tug added this to the Future milestone Jun 17, 2019
@Tug Tug self-assigned this Jun 17, 2019
@Tug Tug requested a review from gziolo June 17, 2019 10:10
@gziolo
Copy link
Member

gziolo commented Jun 17, 2019

What kind of error do you see in React Native? There is no such attribute like style for this block so I don't think this proposal will work as expected.

@Tug
Copy link
Contributor Author

Tug commented Jun 17, 2019

@gziolo The error is mentioned in the PR description.
Indeed the isEligible change isn't useful I'm still experimenting but I think I understood how it works now. Tell me if I'm wrong:

  • Blocks markup is parsed, and for each block we run block validation first
  • If block validation fails we run deprecated blocks alternatives with the parsed attributes and check if there is an eligible one. If there is one it replaces the default one?
  • If no eligible block is found we still try to create the default one using the parsed attributes.
  • In the case of a change in markup, because of a change in implementation in the block save function (like you did in Block library: Refactor Heading block to use class names for text align #16035), the new markup is created and the post content is automatically saved, without asking for user consent.

@Tug Tug added the [Status] In Progress Tracking issues with work in progress label Jun 17, 2019
@Tug
Copy link
Contributor Author

Tug commented Jun 17, 2019

The problem we're having in RN is those console.error calls in https://github.com/WordPress/gutenberg/blob/master/packages/blocks/src/api/validation.js#L635
They show an error screen on RN which can be dismissed of course, but also confused with a real error. The ideal would be to have those displayed as errors when block validation fails and they cannot be created/migrated automatically. Otherwise a console.warn would be more appropriate, what do you think?

@gziolo
Copy link
Member

gziolo commented Jun 18, 2019

The problem we're having in RN is those console.error calls in https://github.com/WordPress/gutenberg/blob/master/packages/blocks/src/api/validation.js#L635
They show an error screen on RN which can be dismissed of course, but also confused with a real error. The ideal would be to have those displayed as errors when block validation fails and they cannot be created/migrated automatically. Otherwise a console.warn would be more appropriate, what do you think?

Yes, everything makes sense in what you said. In general, the block you shared gets migrated to the latest version when you use it in the web context, but the error message is confusing. It gives a false impression that something went wrong. In fact, I would be in favor of using console.info in the case when migration was successful to let the developer know that deprecation logic was triggered and let them debug which one was exactly applied.

I think we can update handling of the following error as well:

log.error(
'Block validation failed for `%s` (%o).\n\nContent generated by `save` function:\n\n%s\n\nContent retrieved from post body:\n\n%s',
blockType.name,
blockType,
generatedBlockContent,
originalBlockContent
);

In both cases, if there is any deprecated version which matches the content saved, we should never print an error to the console.

@gziolo
Copy link
Member

gziolo commented Jun 18, 2019

Yes, this is automated as it's developer's role to provide migration logic which ensures there is no content loss. The assumption is that the developer knows what to do :)

@getdave
Copy link
Contributor

getdave commented Aug 13, 2019

I'm also seeing this error on web.

Screen Shot 2019-08-13 at 13 12 25

@gziolo
Copy link
Member

gziolo commented Aug 13, 2019

I have PR started which will be less dramatic when the block is updated based on the deprecation logic:
#16862

It needs some further refinements but overall it shows the direction.

@gziolo
Copy link
Member

gziolo commented Sep 26, 2019

I have PR started which will be less dramatic when the block is updated based on the deprecation logic:
#16862

Can we consider this PR as resolved now that #16862 was merged? It should warn now less frequently and in more appropriate cases. There still might be some duplication of messages for nested blocks. I plan to tackle it later.

@gziolo gziolo added the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Sep 26, 2019
@Tug Tug closed this Dec 19, 2019
@Tug Tug deleted the rnmobile/try/fix-block-validation-errors branch December 19, 2019 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change) [Status] In Progress Tracking issues with work in progress [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants