Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion packages/block-library/src/template-part/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const init = () => {
return false;
}
}
return true;
return canInsert;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I couldn't find any reason why this returned true instead of canInsert.

}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,27 @@ export default function ConvertToTemplatePart( { clientIds, blocks } ) {
const { replaceBlocks } = useDispatch( blockEditorStore );
const { createSuccessNotice } = useDispatch( noticesStore );

const { isBlockBasedTheme, canCreate } = useSelect( ( select ) => {
return {
isBlockBasedTheme:
select( coreStore ).getCurrentTheme()?.is_block_theme,
canCreate:
select( blockEditorStore ).canInsertBlockType(
'core/template-part'
const clientId = clientIds?.[ 0 ];
const { isBlockBasedTheme, canCreate } = useSelect(
( select ) => {
const { getBlockRootClientId, canInsertBlockType } =
select( blockEditorStore );

const rootClientId = clientId
? getBlockRootClientId( clientId )
: undefined;

return {
isBlockBasedTheme:
select( coreStore ).getCurrentTheme()?.is_block_theme,
canCreate: canInsertBlockType(
'core/template-part',
rootClientId
),
};
}, [] );
};
},
[ clientId ]
);

if ( ! isBlockBasedTheme || ! canCreate ) {
return null;
Expand Down
Loading