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

Site Editor: Don't register the Footnotes block #52823

Closed
wants to merge 4 commits into from
Closed
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
5 changes: 2 additions & 3 deletions packages/block-library/src/footnotes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Copy link
Member

Choose a reason for hiding this comment

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

Regarding the comment above, this does register the format when the block is registered, but I feel like it should be tied closer to block type registration AND reregistration since these two depend on each other. Any ideas?

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe we can use side-effect and blocks.registerBlockType register format when footnotes. But I don't see a corresponding unregister filter in the blocks package.

Copy link
Member

Choose a reason for hiding this comment

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

What do folks think? Is the absence of a blocks.deregisterBlockType hook a blocker?

initBlock( { name, metadata, settings } );
};
4 changes: 3 additions & 1 deletion packages/edit-site/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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' );
Expand Down
19 changes: 15 additions & 4 deletions test/integration/helpers/integration-test-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 (
<ShortcutProvider>
Expand Down
Loading