gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Separator block made with text expansion doesn't use default block variation

Open mrwweb opened this issue 9 months ago • 4 comments

Description

It is possible to register a default block variation to customize the settings of any block, including the Separator.

This works when inserting the separator in most ways, but not when creating a separator by typing --- + ENTER.

I would expect all new blocks to use the default block variation settings regardless of how they are created.

Step-by-step reproduction instructions

  1. Register a default block variation for the Separator (see code below)
  2. Insert Separator block using block inserter.
  3. Observe correct variation is used with div instead of hr
  4. Type --- and ENTER to make a Separator block.
  5. Observe that the Separator block is still using the hr element, contrary to the default block variation
namespace Gutenberg\Bug\Report;

add_filter( 'get_block_type_variations', __NAMESPACE__ . '\block_variations', 10, 2 );
/**
 * Register block variations in PHP for the block editor
 *
 * @param array $variations array of arrays for each block's variations
 * @param object $block block meta for each block, useful for checking $block->name to target a specific block
 * @return array $variations updated array containing variations to register
 */
function block_variations( $variations, $block ) {
	$block_name = $block->name;
	switch ( $block_name ) {
		// use non-semantic separator by default
		case 'core/separator':
			$variations[] = [
				'name' => 'separator',
				'isDefault' => true,
				'attributes' => [
					'tagName' => 'div',
				],
			];
			break;
	}

	return $variations;
}

Screenshots, screen recording, code snippet

No response

Environment info

  • WP 6.9.1
  • Custom Theme
  • No Gutenberg plugin

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

  • [x] Yes

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

  • [x] Yes

Please confirm which theme type you used for testing.

  • [ ] Block
  • [ ] Classic
  • [x] Hybrid (e.g. classic with theme.json)
  • [ ] Not sure

mrwweb avatar Feb 05 '26 16:02 mrwweb

In my current setup, I’m not able to reproduce this issue. It would be really helpful if you could share a bit more detail about the scenario you’re encountering. If possible, a screen recording or any additional context would make it easier to investigate further.

For reference, I’ve attached a video below showing my attempt to reproduce the issue on my end.

https://github.com/user-attachments/assets/4d08d776-f60b-4ae3-9436-04f54e6d6ec2

Mustafabharmal avatar Feb 06 '26 14:02 Mustafabharmal

@Mustafabharmal Interesting. I will try to dig in and see if I can find any other details required to reproduce. Were you using the exact PHP code I shared?

mrwweb avatar Feb 06 '26 21:02 mrwweb

Yup I was using the same code.

Mustafabharmal avatar Feb 07 '26 22:02 Mustafabharmal

Reproduction Report

Description

✅ This report validates that the issue can be reproduced.

Environment

  • WordPress: 7.1-alpha-62201
  • PHP: 8.3.30
  • Server: Apache/2.4.66 (Debian)
  • Database: mysqli (Server: 11.8.6-MariaDB-ubu2404 / Client: mysqlnd 8.3.30)
  • Browser: Chrome 146.0.0.0
  • OS: macOS
  • Theme: Twenty Twenty-Five 1.4
  • MU Plugins: None activated
  • Plugins:
    • Gutenberg 22.9.0-rc.1
    • Test Reports 1.2.1

Actual Results

  • ✅ Error condition occurs (reproduced).
  • The Separator block created via markdown transformation ignores the registered default variation. It renders using the default hr element instead of div.

Additional Notes

  • Hey @mrwweb, thanks for reporting the issue! I was able to reproduce this on the latest Gutenberg/WordPress version as well.
  • On checking the transformation logic for this block, it appears that during markdown matching, a Separator block is created directly without applying attributes from registered variations.
  • I’ll take a closer look at this part of the transformation logic and submit a fix PR soon if it looks appropriate.

Supplemental Artifacts

Image

BugReportOnWeb avatar Apr 07 '26 14:04 BugReportOnWeb