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

Blocks: fix block variation name checking #64818

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from

Conversation

meteorlxy
Copy link
Contributor

@meteorlxy meteorlxy commented Aug 27, 2024

What?

When registering block variations in array:

registerBlockVariation( 'core/variation-block', [
	{
		name: 'variation-name',
		title: 'Variation Title',
		description: 'Variation description',
	},
	{
		name: 'variation-name-2',
		title: 'Variation Title 2',
		description: 'Variation description 2',
	},
] );

There would always have a warning in console:

image

Why?

Fix the wrong warning

How?

Check if the variation param is an array or not

Testing Instructions

Testing Instructions for Keyboard

Screenshots or screencast

Copy link

github-actions bot commented Aug 27, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: meteorlxy <meteorlxy@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@Mamaduka Mamaduka added Needs Decision Needs a decision to be actionable or relevant [Feature] Block Variations Block variations, including introducing new variations and variations as a feature labels Aug 27, 2024
@Mamaduka
Copy link
Member

Thanks for contributing, @meteorlxy!

As the function name suggests, the registerBlockVariation isn't meant to register multiple variations. The fact that it was able to do so is an unaccounted side-effect.

I think we should first consider whether we want to support or discourage this behavior.

@Mamaduka Mamaduka added the [Type] Bug An existing feature does not function as intended label Aug 27, 2024
@meteorlxy
Copy link
Contributor Author

meteorlxy commented Aug 27, 2024

@Mamaduka Oh didn't know that.

The types definition in the @types/wordpress__blocks package is the key reason that why we thought array is supported:

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/d5a5c3b0ef50b7277750ed631c3d640b27272143/types/wordpress__blocks/api/registration.d.ts#L192-L198

Then maybe creating official typings would help discourage this behavior

@Mamaduka
Copy link
Member

JSDoc states that it accepts a variation object:

* @param {string} blockName Name of the block (example: “core/columns”).
* @param {WPBlockVariation} variation Object describing a block variation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block Variations Block variations, including introducing new variations and variations as a feature Needs Decision Needs a decision to be actionable or relevant [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants