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

Block editor: hooks: avoid BlockEdit filter for content locking UI #56957

Merged
merged 1 commit into from
Dec 11, 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
31 changes: 5 additions & 26 deletions packages/block-editor/src/hooks/content-lock-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
* WordPress dependencies
*/
import { ToolbarButton, MenuItem } from '@wordpress/components';
import { createHigherOrderComponent, pure } from '@wordpress/compose';
import { useDispatch, useSelect } from '@wordpress/data';
import { addFilter } from '@wordpress/hooks';
import { __ } from '@wordpress/i18n';
import { useEffect, useRef, useCallback } from '@wordpress/element';

Expand Down Expand Up @@ -147,28 +145,9 @@ function ContentLockControlsPure( { clientId, isSelected } ) {
);
}

// We don't want block controls to re-render when typing inside a block. `pure`
// will prevent re-renders unless props change, so only pass the needed props
// and not the whole attributes object.
const ContentLockControls = pure( ContentLockControlsPure );

export const withContentLockControls = createHigherOrderComponent(
( BlockEdit ) => ( props ) => {
return (
<>
<ContentLockControls
clientId={ props.clientId }
isSelected={ props.isSelected }
/>
<BlockEdit key="edit" { ...props } />
</>
);
export default {
edit: ContentLockControlsPure,
hasSupport() {
return true;
},
'withContentLockControls'
);

addFilter(
'editor.BlockEdit',
'core/content-lock-ui/with-block-controls',
withContentLockControls
);
};
Loading