Separator block made with text expansion doesn't use default block variation
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
- Register a default block variation for the Separator (see code below)
- Insert Separator block using block inserter.
- Observe correct variation is used with
divinstead ofhr - Type
---andENTERto make a Separator block. - Observe that the Separator block is still using the
hrelement, 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
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 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?
Yup I was using the same code.
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
hrelement instead ofdiv.
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.