diff --git a/packages/block-library/src/post-content/edit.js b/packages/block-library/src/post-content/edit.js index fcdb14198d7b10..88ee3d2098b63d 100644 --- a/packages/block-library/src/post-content/edit.js +++ b/packages/block-library/src/post-content/edit.js @@ -7,7 +7,9 @@ import { useBlockProps, __experimentalUseInnerBlocksProps as useInnerBlocksProps, __experimentalUseEditorFeature as useEditorFeature, + __experimentalUseNoRecursiveRenders as useNoRecursiveRenders, store as blockEditorStore, + Warning, } from '@wordpress/block-editor'; import { useEntityBlockEditor } from '@wordpress/core-data'; @@ -55,19 +57,41 @@ function Placeholder() { ); } +function RecursionError() { + const blockProps = useBlockProps(); + return ( +
%s. Block cannot be rendered inside itself.' ),
+ $post_id
+ ),
+ E_USER_WARNING
+ );
+ }
+
+ $is_debug = defined( 'WP_DEBUG' ) && WP_DEBUG &&
+ defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG_DISPLAY;
+ return $is_debug ?
+ // translators: Visible only in the front end, this warning takes the place of a faulty block.
+ __( '[block rendering halted]' ) :
+ '';
+ }
+
+ $seen_ids[ $post_id ] = true;
+
if ( ! in_the_loop() ) {
the_post();
}
- $content = get_the_content( null, false, $block->context['postId'] );
+ $content = get_the_content( null, false, $post_id );
if ( empty( $content ) ) {
+ unset( $seen_ids[ $post_id ] );
return '';
}
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => 'entry-content' ) );
+ /** This filter is documented in wp-includes/post-template.php */
+ $content = apply_filters( 'the_content', str_replace( ']]>', ']]>', $content ) );
+ unset( $seen_ids[ $post_id ] );
return (
'