Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid showing the recursion warning in previews when replacing template parts #44256

Merged
merged 1 commit into from
Sep 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 60 additions & 58 deletions packages/block-library/src/template-part/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,64 +133,66 @@ export default function TemplatePartEdit( {
}

return (
<RecursionProvider uniqueId={ templatePartId }>
<TemplatePartAdvancedControls
tagName={ tagName }
setAttributes={ setAttributes }
isEntityAvailable={ isEntityAvailable }
templatePartId={ templatePartId }
defaultWrapper={ areaObject.tagName }
/>
{ isPlaceholder && (
<TagName { ...blockProps }>
<TemplatePartPlaceholder
area={ attributes.area }
templatePartId={ templatePartId }
clientId={ clientId }
setAttributes={ setAttributes }
onOpenSelectionModal={ () =>
setIsTemplatePartSelectionOpen( true )
}
/>
</TagName>
) }
{ canReplace && (
<BlockSettingsMenuControls>
{ () => (
<MenuItem
onClick={ () => {
setIsTemplatePartSelectionOpen( true );
} }
>
{ createInterpolateElement(
__( 'Replace <BlockTitle />' ),
{
BlockTitle: (
<BlockTitle
clientId={ clientId }
maximumLength={ 25 }
/>
),
}
) }
</MenuItem>
) }
</BlockSettingsMenuControls>
) }
{ isEntityAvailable && (
<TemplatePartInnerBlocks
tagName={ TagName }
blockProps={ blockProps }
postId={ templatePartId }
hasInnerBlocks={ innerBlocks.length > 0 }
layout={ layout }
<>
<RecursionProvider uniqueId={ templatePartId }>
<TemplatePartAdvancedControls
tagName={ tagName }
setAttributes={ setAttributes }
isEntityAvailable={ isEntityAvailable }
templatePartId={ templatePartId }
defaultWrapper={ areaObject.tagName }
/>
) }
{ ! isPlaceholder && ! isResolved && (
<TagName { ...blockProps }>
<Spinner />
</TagName>
) }
{ isPlaceholder && (
<TagName { ...blockProps }>
<TemplatePartPlaceholder
area={ attributes.area }
templatePartId={ templatePartId }
clientId={ clientId }
setAttributes={ setAttributes }
onOpenSelectionModal={ () =>
setIsTemplatePartSelectionOpen( true )
}
/>
</TagName>
) }
{ canReplace && (
<BlockSettingsMenuControls>
{ () => (
<MenuItem
onClick={ () => {
setIsTemplatePartSelectionOpen( true );
} }
>
{ createInterpolateElement(
__( 'Replace <BlockTitle />' ),
{
BlockTitle: (
<BlockTitle
clientId={ clientId }
maximumLength={ 25 }
/>
),
}
) }
</MenuItem>
) }
</BlockSettingsMenuControls>
) }
{ isEntityAvailable && (
<TemplatePartInnerBlocks
tagName={ TagName }
blockProps={ blockProps }
postId={ templatePartId }
hasInnerBlocks={ innerBlocks.length > 0 }
layout={ layout }
/>
) }
{ ! isPlaceholder && ! isResolved && (
<TagName { ...blockProps }>
<Spinner />
</TagName>
) }
</RecursionProvider>
{ isTemplatePartSelectionOpen && (
<Modal
overlayClassName="block-editor-template-part__selection-modal"
Expand All @@ -215,6 +217,6 @@ export default function TemplatePartEdit( {
/>
</Modal>
) }
</RecursionProvider>
</>
);
}