diff --git a/packages/block-library/src/index.js b/packages/block-library/src/index.js index c962c8172dec6..870b0cc665625 100644 --- a/packages/block-library/src/index.js +++ b/packages/block-library/src/index.js @@ -174,7 +174,9 @@ export const registerCoreBlocks = () => { /** * Function to register experimental core blocks depending on editor settings. * - * @param {Object} settings Editor settings. + * @param {Object} settings Editor settings. + * @param {Object} [context] Post context. + * @param {string} [context.postType] Post Type * * @example * ```js @@ -185,7 +187,7 @@ export const registerCoreBlocks = () => { */ export const __experimentalRegisterExperimentalCoreBlocks = process.env.GUTENBERG_PHASE === 2 - ? ( settings ) => { + ? ( settings, { postType } = {} ) => { const { __experimentalEnableLegacyWidgetBlock, __experimentalEnableFullSiteEditing, @@ -208,7 +210,16 @@ export const __experimentalRegisterExperimentalCoreBlocks = queryLoop, queryPagination, postTitle, - postContent, + /* + * Only provide the Post Content block when editing templates or, + * template parts so there's no risk of posts including themselves + * through a Post Content block (leading to infinite recursion). + */ + [ 'wp_template', 'wp_template_part' ].includes( + postType + ) + ? postContent + : null, postAuthor, postComments, postCommentsCount, @@ -217,7 +228,7 @@ export const __experimentalRegisterExperimentalCoreBlocks = postExcerpt, postFeaturedImage, postTags, - ] + ].filter( Boolean ) : [] ), ].forEach( registerBlock ); } diff --git a/packages/edit-post/src/index.js b/packages/edit-post/src/index.js index 2bd1cc75e0751..59d013e7ebe43 100644 --- a/packages/edit-post/src/index.js +++ b/packages/edit-post/src/index.js @@ -96,7 +96,7 @@ export function initializeEditor( ); registerCoreBlocks(); if ( process.env.GUTENBERG_PHASE === 2 ) { - __experimentalRegisterExperimentalCoreBlocks( settings ); + __experimentalRegisterExperimentalCoreBlocks( settings, { postType } ); } // Show a console log warning if the browser is not in Standards rendering mode. diff --git a/packages/edit-site/src/index.js b/packages/edit-site/src/index.js index 08a0e3993f0e9..10cccc717e66d 100644 --- a/packages/edit-site/src/index.js +++ b/packages/edit-site/src/index.js @@ -58,7 +58,9 @@ export function initialize( id, settings ) { registerCoreBlocks(); if ( process.env.GUTENBERG_PHASE === 2 ) { - __experimentalRegisterExperimentalCoreBlocks( settings ); + __experimentalRegisterExperimentalCoreBlocks( settings, { + postType: 'wp_template', + } ); } render( , document.getElementById( id ) ); diff --git a/test/integration/full-content/full-content.test.js b/test/integration/full-content/full-content.test.js index 008239bd612b6..040001690a82d 100644 --- a/test/integration/full-content/full-content.test.js +++ b/test/integration/full-content/full-content.test.js @@ -73,7 +73,15 @@ describe( 'full post content fixture', () => { require( '../../../packages/editor/src/hooks' ); registerCoreBlocks(); if ( process.env.GUTENBERG_PHASE === 2 ) { - __experimentalRegisterExperimentalCoreBlocks( settings ); + /** + * We're loading these blocks with a `wp_template` post context, + * since most of them are meant to be used in Site Editor templates, + * to the point that e.g. the Post Content block is unavailable in + * a Post Editor (`post`) context. + */ + __experimentalRegisterExperimentalCoreBlocks( settings, { + postType: 'wp_template', + } ); } } );