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

Editor: Fix custom sources backwards compatibility for the pages post type. #17820

Merged

Conversation

epiqueras
Copy link
Contributor

Fixes #17767

Description

This PR fixes the custom sources backwards compatibility filter's hook to take into account post types other than post.

How has this been tested?

It was verified that adding blocks with meta sources to pages no longer crashes the editor and an e2e test was added to avoid regressions.

Types of Changes

Bug Fix: Meta sources no longer crash the editor if the edited post is not of post type post.

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.

@epiqueras epiqueras added [Type] Bug An existing feature does not function as intended [Feature] Block API API that allows to express the block paradigm. [Package] Editor /packages/editor labels Oct 7, 2019
@epiqueras epiqueras added this to the Future milestone Oct 7, 2019
@epiqueras epiqueras self-assigned this Oct 7, 2019
@@ -15,7 +16,9 @@ function useMetaAttributeSource( name, _attributes, _setAttributes ) {

if ( Object.values( attributeTypes ).some( ( type ) => type.source === 'meta' ) ) {
// eslint-disable-next-line react-hooks/rules-of-hooks
const [ meta, setMeta ] = useEntityProp( 'postType', 'post', 'meta' );
const { type } = useSelect( ( select ) => select( 'core/editor' ).getCurrentPost(), [] );
Copy link
Contributor

Choose a reason for hiding this comment

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

getCurrentPostType selector maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, we'll need to change it later, but it's better for performance now.

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.

This makes sense to me. I didn't test but I trust the e2e test here.

@epiqueras epiqueras merged commit eec5a1e into master Oct 7, 2019
@epiqueras epiqueras deleted the fix/meta-sources-backwards-compatibility-for-pages branch October 7, 2019 17:51
@youknowriad youknowriad modified the milestones: Future, Gutenberg 6.7 Oct 14, 2019
@luuptekman
Copy link

Came into this issue via #17767.

I'm still experiencing this issue with custom post type (in my case I have created a new post type experiences). When adding a block in custom post edit screen this happens Cannot read property '_my_meta_id' of undefined.

When adding the block in posts/pages, everything is ok. This is the block plugin I'm using to reproduce the issue with WP 5.3.2. https://github.com/luuptek/bokun-wp

@epiqueras
Copy link
Contributor Author

When adding a block in custom post edit screen this happens Cannot read property '_my_meta_id' of undefined.
When adding the block in posts/pages, everything is ok.

Sounds like the core-data store is not bootstrapped correctly. Is getEntityRecord being called for the relevant post before loading the editor?

@luuptekman
Copy link

How can I check that?

@epiqueras
Copy link
Contributor Author

Where is the code for the custom post edit screen?

@luuptekman
Copy link

Where is the code for the custom post edit screen?

Gutenberg related stuff in here: https://github.com/luuptek/bokun-wp/blob/master/src/bokun-product/bokun-product.js ==> _bokun_wp_bokun_id is what it's complaining about...

Meta data is registered via register_post_meta in main plugin file: https://github.com/luuptek/bokun-wp/blob/master/bokun-wp.php

Custom post is added in theme , example via this:

function book_setup_post_type() {
	$args = array(
		'public'    => true,
		'label'     => __( 'Books', 'textdomain' ),
		'menu_icon' => 'dashicons-book',
		'show_in_rest' => true,
	);
	register_post_type( 'book', $args );
}
add_action( 'init', 'book_setup_post_type' );

@epiqueras
Copy link
Contributor Author

When adding a block in custom post edit screen this happens Cannot read property '_my_meta_id' of undefined.

Where is that custom post edit screen?

@luuptekman
Copy link

When adding a block in custom post edit screen this happens Cannot read property '_my_meta_id' of undefined.

Where is that custom post edit screen?

Depends on custom post definition...in example above it would be in Books => Add new

@epiqueras
Copy link
Contributor Author

Sounds like your post type is missing custom-fields support.

https://developer.wordpress.org/reference/functions/register_post_type/

https://developer.wordpress.org/reference/functions/add_post_type_support/

@luuptekman
Copy link

Big thanks for pointing that! So custom post need to support custom-fields ==> will work then 👍

@epiqueras
Copy link
Contributor Author

I'm glad I could help! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm. [Package] Editor /packages/editor [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Blocks with post meta attributes stopped working after update 6.6.0
3 participants