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

Fixes missing default funcs as props in BlockEditorProvider #17036

Merged

Conversation

getdave
Copy link
Contributor

@getdave getdave commented Aug 14, 2019

The component assumes that the onChange and onInput props are always present. However, there are times where this may not be the case such as when the BlockPreview component uses the provider to render the previews. In such cases onChange is called but is undefined which causes an error to be thrown.

To avoid this we provide lodash noop as defaults for both “change” props.

An example of when an error is thrown can be seen in this PR

Automattic/wp-calypso#35333

Questions

  • Should we test for isFunction as well?
  • Is noop a good default?
  • Should I also fix the React Native version? Who do I need to ping about this?

How has this been tested?

Running this branch against Automattic/wp-calypso#35333 causes the error related to onChange to disappear.

Types of changes

Bug fix (non-breaking change which fixes an issue)

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.

Previously the component assumed that the onChange and onInput props would always be present. However, there are times where this may not be the case such as when the BlockPreview component uses the provider to render the previews. In such cases `onChange` is called but is undefined which causes an error to be thrown.

To avoid this we provide lodash noop as defaults for both “change” props.
@getdave getdave added the [Package] Block editor /packages/block-editor label Aug 14, 2019
@getdave getdave requested a review from youknowriad August 14, 2019 12:50
@getdave getdave self-assigned this Aug 14, 2019
@getdave getdave requested a review from retrofox August 14, 2019 13:03
Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

That makes sense to me but I'm wondering why these get called in previews? This could hint to a hidden bug where we're calling onChange where we shouldn't.

@getdave getdave merged commit d83c239 into master Aug 15, 2019
@getdave getdave deleted the fix/block-editor-provider-ensure-default-change-props branch August 15, 2019 15:06
@senadir senadir added this to the Gutenberg 6.4 milestone Aug 25, 2019
jeremyfelt added a commit to bu-ist/bu-blocks that referenced this pull request Aug 26, 2019
In the latest version of WordPress and Gutenberg, it's possible
the `onChange` function does not exist by default on block
components.

This change checks that `onChange` is callable before attempting to
call it.

This will likely be fixed in future versionso of Gutenberg via
WordPress/gutenberg#17036, but it won't
hurt to have a fallback check here.
gziolo pushed a commit that referenced this pull request Aug 29, 2019
Previously the component assumed that the onChange and onInput props would always be present. However, there are times where this may not be the case such as when the BlockPreview component uses the provider to render the previews. In such cases `onChange` is called but is undefined which causes an error to be thrown.

To avoid this we provide lodash noop as defaults for both “change” props.
gziolo pushed a commit that referenced this pull request Aug 29, 2019
Previously the component assumed that the onChange and onInput props would always be present. However, there are times where this may not be the case such as when the BlockPreview component uses the provider to render the previews. In such cases `onChange` is called but is undefined which causes an error to be thrown.

To avoid this we provide lodash noop as defaults for both “change” props.
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants