Skip to content
Merged
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
14 changes: 3 additions & 11 deletions packages/block-editor/src/hooks/allowed-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,17 @@
*/
import { addFilter } from '@wordpress/hooks';
import { hasBlockSupport } from '@wordpress/blocks';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import { store as blockEditorStore } from '../store';
import { PrivateInspectorControlsAllowedBlocks } from '../components/inspector-controls/groups';
import BlockAllowedBlocksControl from '../components/block-allowed-blocks/allowed-blocks-control';
import { useBlockEditingMode } from '../components/block-editing-mode';

function BlockEditAllowedBlocksControlPure( { clientId } ) {
const isContentOnly = useSelect(
( select ) => {
return (
select( blockEditorStore ).getBlockEditingMode( clientId ) ===
'contentOnly'
);
},
[ clientId ]
);
const blockEditingMode = useBlockEditingMode();
const isContentOnly = blockEditingMode === 'contentOnly';
Comment on lines +15 to +16

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@Mamaduka - I believe you mentioned somewhere that useBlockEditingMode is faster than adding getBlockEditingMode. Trying to make it stick in my brain and make sure I got it right :)

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.

Right. It should be preferred over custom useSelect. The useBlockEditingMode uses block context when possible and avoids creating a store subscription.

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.

With how many total subscriptions we maintain in runtime, I imagine the actual performance impact is hard to pinpoint? I was mostly curious how we choose what to prioritize when spending time on performance.

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.

In my experience, similar optimizations have a small impact and are hard to measure. These components are rendered only when the block is selected and don't create a subscription for every block on the canvas. But fixing similar paper cuts is a good thing.

I think fixes like #72496 are more impactful. The RichText can be rendered on canvas hundreds or thousands of times,

Personally, I do similar optimizations if it's a small change and doesn't complicate the logic. Otherwise, it's hard to justify complexity without real measurements.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I share the same opinion as @Mamaduka. It's one of those bottle pickup things that is hard to measure in the moment, but is noticeable over time.

I've been looking at a lot of performance issues this week. As I happen across subscriptions that can be combined or easily prevented from running without adding complexity, I'm adding them to #72535 so I don't forget about them.

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.

Small steps lead to big changes!


if ( isContentOnly ) {
return null;
Expand Down
Loading