Skip to content

Commit

Permalink
Footnotes: Register format within the init function (#63554)
Browse files Browse the repository at this point in the history
Co-authored-by: youknowriad <[email protected]>
Co-authored-by: ellatrix <[email protected]>
  • Loading branch information
3 people authored Jul 15, 2024
1 parent abed060 commit 34cadb6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
3 changes: 1 addition & 2 deletions packages/block-library/src/footnotes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ export const settings = {
edit,
};

registerFormatType( formatName, format );

export const init = () => {
registerFormatType( formatName, format );
initBlock( { name, metadata, settings } );
};
6 changes: 5 additions & 1 deletion packages/core-data/src/test/entity-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
} from '@wordpress/blocks';
import { RichText, useBlockProps } from '@wordpress/block-editor';
import { createRegistry, RegistryProvider } from '@wordpress/data';
import '@wordpress/block-library';
import { registerCoreBlocks } from '@wordpress/block-library';
import { unregisterFormatType } from '@wordpress/rich-text';

/**
* Internal dependencies
Expand Down Expand Up @@ -137,12 +138,15 @@ describe( 'useEntityBlockEditor', () => {
title: 'block title',
edit,
} );

registerCoreBlocks();
} );

afterEach( () => {
getBlockTypes().forEach( ( block ) => {
unregisterBlockType( block.name );
} );
unregisterFormatType( 'core/footnote' );
} );

it( 'does not mutate block attributes that include an array of strings or null values', async () => {
Expand Down
11 changes: 10 additions & 1 deletion test/integration/helpers/integration-test-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ import {
unregisterBlockType,
getBlockTypes,
} from '@wordpress/blocks';
import {
store as richTextStore,
unregisterFormatType,
} from '@wordpress/rich-text';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
Expand Down Expand Up @@ -58,14 +63,18 @@ export async function selectBlock( name ) {

export function Editor( { testBlocks, settings = {} } ) {
const [ currentBlocks, updateBlocks ] = useState( testBlocks );
const { getFormatTypes } = useSelect( richTextStore );

useEffect( () => {
return () => {
getBlockTypes().forEach( ( { name } ) =>
unregisterBlockType( name )
);
getFormatTypes().forEach( ( { name } ) =>
unregisterFormatType( name )
);
};
}, [] );
}, [ getFormatTypes ] );

return (
<BlockEditorProvider
Expand Down

0 comments on commit 34cadb6

Please sign in to comment.