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 variations registered on the server can get overwritten in the client #60298

Closed
joemcgill opened this issue Mar 29, 2024 · 2 comments · Fixed by #60832
Closed

Block variations registered on the server can get overwritten in the client #60298

joemcgill opened this issue Mar 29, 2024 · 2 comments · Fixed by #60832
Assignees
Labels
[Feature] Block Variations Block variations, including introducing new variations and variations as a feature [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@joemcgill
Copy link
Member

Description

As reported in https://core.trac.wordpress.org/ticket/60856, the core/group block does not register any of its variations on the server, but instead adds them at runtime in the client. This means that any variations registered on the server via filters or other means get overwritten when the core/group block is initialized. I suspect this behavior is consistent with all blocks that are adding variations, which likely includes this whole list.

I would expect that any variations supplied by the server would be added to the variations added to the block in JS.

Step-by-step reproduction instructions

  1. Add a block variation to the group block using the get_block_type_variations filter in PHP.
  2. Confirm that the variation is being supplied by the server by inspecting the output of get_block_editor_server_block_settings(), which is used to bootstrap block types from the server.
  3. Load the editor and inspect the block definition in the console: wp.blocks.getBlockTypes().filter( (block) => block.name === 'core/group' )
  4. See that the variation supplied by the server is no longer present.

Screenshots, screen recording, code snippet

No response

Environment info

No response

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@joemcgill joemcgill added [Type] Bug An existing feature does not function as intended [Feature] Block Variations Block variations, including introducing new variations and variations as a feature labels Mar 29, 2024
@t-hamano
Copy link
Contributor

I was also able to reproduce the problem. I tested it with the code below.

function modify_block_type_variations( $variations, $block_type ) {
	// This variation will be registered.
	if ( 'core/paragraph' === $block_type->name ) {
		$variations[] = array(
			'name'  => 'paragraph-variation',
			'title' => 'New Paragraph Variation',
		);
	}
	// This variation will be registered.
	if ( 'core/heading' === $block_type->name ) {
		$variations[] = array(
			'name'  => 'heading-variation',
			'title' => 'New Heading Variation',
		);
	}
	// This variation will not be registered.
	if ( 'core/group' === $block_type->name ) {
		$variations[] = array(
			'name'  => 'group-variation',
			'title' => 'New Group Variation',
		);
	}
	// This variation will not be registered.
	if ( 'core/columns' === $block_type->name ) {
		$variations[] = array(
			'name'  => 'columns-variation',
			'title' => 'New Columns Variation',
		);
	}
	return $variations;
}
add_filter( 'get_block_type_variations', 'modify_block_type_variations', 10, 2 );

@Mamaduka
Copy link
Member

Mamaduka commented Apr 17, 2024

Can you add more variations using JS when initial variations are coming from the server?

Update: You can due to the native of the bug. I've some ideas on how to fix it.

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 [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants