Remove regressed useForcedLayout logic

This commit is contained in:
Mike Jolley 2022-12-15 15:39:36 +00:00 committed by Nadir Seghir
parent 963c8dcebe
commit 020d9f3919
1 changed files with 1 additions and 56 deletions

View File

@ -122,45 +122,6 @@ export const useForcedLayout = ( {
.select( 'core/block-editor' ) .select( 'core/block-editor' )
.getBlocks( clientId ); .getBlocks( clientId );
const { innerBlocks, registeredBlockTypes } = useSelect(
( select ) => {
return {
innerBlocks:
select( 'core/block-editor' ).getBlocks( clientId ),
registeredBlockTypes: currentRegisteredBlocks.current.map(
( blockName ) => getBlockType( blockName )
),
};
},
[ clientId, currentRegisteredBlocks.current ]
);
const appendBlock = useCallback(
( block, position ) => {
const newBlock = createBlock( block.name );
insertBlock( newBlock, position, clientId, false );
},
// We need to skip insertBlock here due to a cache issue in wordpress.com that causes an infinite loop, see https://github.com/Automattic/wp-calypso/issues/66092 for an expanded doc.
// eslint-disable-next-line react-hooks/exhaustive-deps
[ clientId ]
);
const lockedBlockTypes = useMemo(
() =>
registeredBlockTypes.filter(
( block: Block | undefined ) => block && isBlockLocked( block )
),
[ registeredBlockTypes ]
) as Block[];
/**
* If the current inner blocks differ from the registered blocks, push the differences.
*/
useLayoutEffect( () => {
if ( ! clientId ) {
return;
}
// If there are NO inner blocks, sync with the given template. // If there are NO inner blocks, sync with the given template.
if ( if (
innerBlocks.length === 0 && innerBlocks.length === 0 &&
@ -175,22 +136,6 @@ export const useForcedLayout = ( {
} }
} }
// Find registered locked blocks missing from Inner Blocks and append them.
lockedBlockTypes.forEach( ( block ) => {
// If the locked block type is already in the layout, we can skip this one.
if (
innerBlocks.length === 0 &&
currentDefaultTemplate.current.length > 0
) {
const nextBlocks = createBlocksFromInnerBlocksTemplate(
currentDefaultTemplate.current
);
if ( ! isEqual( nextBlocks, innerBlocks ) ) {
replaceInnerBlocks( clientId, nextBlocks );
return;
}
}
const registeredBlockTypes = currentRegisteredBlocks.current.map( const registeredBlockTypes = currentRegisteredBlocks.current.map(
( blockName: string ) => getBlockType( blockName ) ( blockName: string ) => getBlockType( blockName )
); );