diff --git a/packages/block-library/src/footnotes/index.js b/packages/block-library/src/footnotes/index.js index c0f3d60ada5432..db9782cb567677 100644 --- a/packages/block-library/src/footnotes/index.js +++ b/packages/block-library/src/footnotes/index.js @@ -21,9 +21,8 @@ export const settings = { edit, }; -// Would be good to remove the format and HoR if the block is unregistered. -registerFormatType( formatName, format ); - export const init = () => { + // Would be good to remove the format if the block is unregistered. + registerFormatType( formatName, format ); initBlock( { name, metadata, settings } ); }; diff --git a/packages/edit-site/src/index.js b/packages/edit-site/src/index.js index ea2899a8abc105..818c8285933a02 100644 --- a/packages/edit-site/src/index.js +++ b/packages/edit-site/src/index.js @@ -29,6 +29,8 @@ import './hooks'; import { store as editSiteStore } from './store'; import App from './components/app'; +const DISALLOWED_BLOCKS = [ 'core/freeform', 'core/footnotes' ]; + /** * Initializes the site editor screen. * @@ -45,7 +47,7 @@ export function initializeEditor( id, settings ) { dispatch( blocksStore ).__experimentalReapplyBlockTypeFilters(); const coreBlocks = __experimentalGetCoreBlocks().filter( - ( { name } ) => name !== 'core/freeform' + ( { name } ) => ! DISALLOWED_BLOCKS.includes( name ) ); registerCoreBlocks( coreBlocks ); dispatch( blocksStore ).setFreeformFallbackBlockName( 'core/html' ); diff --git a/test/integration/helpers/integration-test-editor.js b/test/integration/helpers/integration-test-editor.js index 6b954a895a51ac..7d5b3d9120509c 100644 --- a/test/integration/helpers/integration-test-editor.js +++ b/test/integration/helpers/integration-test-editor.js @@ -26,6 +26,8 @@ import { unregisterBlockType, getBlockTypes, } from '@wordpress/blocks'; +import { store as richTextStore } from '@wordpress/rich-text'; +import { useSelect, useDispatch } from '@wordpress/data'; /** * Internal dependencies @@ -60,13 +62,22 @@ export async function selectBlock( name ) { export function Editor( { testBlocks, settings = {} } ) { const [ currentBlocks, updateBlocks ] = useState( testBlocks ); + // Some blocks may register formats, eg. core/footnotes, so we need to also + // unregister those formats along with core blocks when the test is complete. + const availableFormats = useSelect( + ( select ) => select( richTextStore ).getFormatTypes(), + [] + ); + const { removeFormatTypes } = useDispatch( richTextStore ); + useEffect( () => { return () => { - getBlockTypes().forEach( ( { name } ) => - unregisterBlockType( name ) - ); + getBlockTypes().forEach( ( { name } ) => { + unregisterBlockType( name ); + } ); + removeFormatTypes( availableFormats.map( ( { name } ) => name ) ); }; - }, [] ); + }, [ availableFormats, removeFormatTypes ] ); return (