Skip to content

Commit

Permalink
Fix aborted rendering of non-nested reusable blocks
Browse files Browse the repository at this point in the history
Since #28405, `render_block_core_block` prevents fatal rendering loops
in Reusable Blocks by aborting if a given block has already been
rendered. This effectively prevents loops, but also unintentionally
prevented the same reusable block from being rendered twice on the same
page, even if one isn't nested in the other.

This commit fixes this by explicitly forgetting a Reusable Block after
it has finished rendering.
  • Loading branch information
mcsf committed Jan 25, 2021
1 parent 437a546 commit 0ba895b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/block-library/src/block/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function render_block_core_block( $attributes ) {
return '';
}

if ( in_array( $attributes['ref'], $seen_refs, true ) ) {
if ( isset( $seen_refs[ $attributes['ref'] ] ) ) {
if ( ! is_admin() ) {
trigger_error(
sprintf(
Expand All @@ -47,13 +47,15 @@ function render_block_core_block( $attributes ) {
'';
}

$seen_refs[] = $attributes['ref'];

if ( 'publish' !== $reusable_block->post_status || ! empty( $reusable_block->post_password ) ) {
return '';
}

return do_blocks( $reusable_block->post_content );
$seen_refs[ $attributes['ref'] ] = true;

$result = do_blocks( $reusable_block->post_content );
unset( $seen_refs[ $attributes['ref'] ] );
return $result;
}

/**
Expand Down

0 comments on commit 0ba895b

Please sign in to comment.