Skip to content

Commit

Permalink
fix: detach layout classnames from inner elements
Browse files Browse the repository at this point in the history
  • Loading branch information
yogeshbhutkar committed Feb 25, 2025
1 parent cc9ccfb commit 951c1ca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
9 changes: 8 additions & 1 deletion packages/block-library/src/comment-template/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,18 @@ function block_core_comment_template_render_comments( $comments, $block ) {
*/
add_filter( 'render_block_context', $filter_block_context, 1 );

// Get an instance of the current Comment Template block.
$block_instance = $block->parsed_block;

// Set the block name to one that does not correspond to an existing registered block.
// This ensures that for the inner instances of the Comment Template block, we do not render any block supports.
$block_instance['blockName'] = 'core/null';

/*
* We construct a new WP_Block instance from the parsed block so that
* it'll receive any changes made by the `render_block_data` filter.
*/
$block_content = ( new WP_Block( $block->parsed_block ) )->render( array( 'dynamic' => false ) );
$block_content = ( new WP_Block( $block_instance ) )->render( array( 'dynamic' => false ) );

remove_filter( 'render_block_context', $filter_block_context, 1 );

Expand Down
1 change: 0 additions & 1 deletion phpunit/blocks/render-comment-template-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ public function test_inner_block_inserted_by_render_block_data_is_retained() {

$args = $render_block_callback->get_args();
$this->assertSame( 'core/comment-content', $args[0][2]->name );
$this->assertSame( 'core/comment-template', $args[1][2]->name );
$this->assertCount( 2, $args[1][2]->inner_blocks, "Inner block inserted by render_block_data filter wasn't retained." );
$this->assertInstanceOf(
'WP_Block',
Expand Down

0 comments on commit 951c1ca

Please sign in to comment.