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

Augment Block.Edit filter docs with performance guidance #55252

Merged
merged 1 commit into from
Oct 16, 2023
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
29 changes: 25 additions & 4 deletions docs/reference-guides/filters/block-filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,7 @@ var withInspectorControls = wp.compose.createHigherOrderComponent( function (
)
);
};
},
'withInspectorControls' );
}, 'withInspectorControls' );

wp.hooks.addFilter(
'editor.BlockEdit',
Expand All @@ -239,6 +238,29 @@ wp.hooks.addFilter(

{% end %}

Note that as this hook is run for _all blocks_, consuming it has potential for performance regressions particularly around block selection metrics.

To mitigate this, consider whether any work you perform can be altered to run only under certain conditions.

For example, if you are adding components that only need to render when the block is _selected_, then you can use the block's "selected" state (`props.isSelected`) to conditionalize your rendering.

```js
const withInspectorControls = createHigherOrderComponent( ( BlockEdit ) => {
return ( props ) => {
return (
<>
<BlockEdit { ...props } />
{ props.isSelected && {
<InspectorControls>
<PanelBody>My custom control</PanelBody>
</InspectorControls>
}}
</>
);
};
}, 'withInspectorControl' );
```

#### `editor.BlockListBlock`

Used to modify the block's wrapper component containing the block's `edit` component and all toolbars. It receives the original `BlockListBlock` component and returns a new wrapped component.
Expand Down Expand Up @@ -288,8 +310,7 @@ var withClientIdClassName = wp.compose.createHigherOrderComponent( function (

return el( BlockListBlock, newProps );
};
},
'withClientIdClassName' );
}, 'withClientIdClassName' );

wp.hooks.addFilter(
'editor.BlockListBlock',
Expand Down