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

Block Merge: guard for undefined attribute definition #17937

Merged
merged 3 commits into from
Nov 6, 2019

Conversation

ellatrix
Copy link
Member

Description

Related: wordpress-mobile/WordPress-iOS#11950. Cc @SergioEstevao.

Currently, when a block implements a merge function, but doesn't set the identifier prop for RichText, merging will error because selection cannot be restored. Instead, we should log an error and let the merge continue without restoring selection.

How has this been tested?

Screenshots

Types of changes

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.

@SergioEstevao
Copy link
Contributor

@ellatrix thanks for adding this check, it will make it a lot easier to detect this problem in the future.

:shipit:

@SergioEstevao SergioEstevao self-requested a review November 4, 2019 13:55
Copy link
Contributor

@SergioEstevao SergioEstevao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ellatrix thanks for adding this check, it will make it a lot easier to detect this problem in the future.

:shipit:

Copy link
Contributor

@talldan talldan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested it, so this review is purely going on the code.

It all makes sense to me, and the code is tidy. I left a couple of minor comments, nothing that should block merging.

packages/block-editor/src/store/effects.js Outdated Show resolved Hide resolved
);

if ( ! attributeDefinition ) {
if ( typeof attributeKey === 'number' ) {
window.console.error(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again this is another minor comment (which I don't think is a blocker for the PR). This seems like a very specific error, and I wonder whether it could be more generic by catching anything where value is defined but the type isn't a string, and adding something like this as the error:

`RichText needs an identifier prop that is the block attribute key of the attribute it controls. Its type is expected to be a string, but was ${ typeof attributeKey }`

@gziolo gziolo added [Type] Bug An existing feature does not function as intended [Package] Block editor /packages/block-editor labels Nov 6, 2019
Co-Authored-By: Daniel Richards <daniel.richards@automattic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Block editor /packages/block-editor [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants