Skip to content

Commit

Permalink
Wrap Edit with bindings logic only when the block supports it
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Nov 28, 2024
1 parent 87ffc28 commit b24d527
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions packages/block-editor/src/components/block-edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { hasBlockSupport } from '@wordpress/blocks';
* Internal dependencies
*/
import Edit from './edit';
import { withBlockBindingSupport } from './with-block-bindings-attributes';
import { withBlockBindingsSupport } from './with-block-bindings-support';
import {
BlockEditContextProvider,
useBlockEditContext,
Expand All @@ -20,6 +20,9 @@ import {
} from './context';
import { MultipleUsageWarning } from './multiple-usage-warning';
import { PrivateBlockContext } from '../block-list/private-block-context';
import { canBindBlock } from '../../utils/block-bindings';

const BlockEditWithBindings = withBlockBindingsSupport( Edit );

/**
* The `useBlockEditContext` hook provides information about the block this hook is being used in.
Expand All @@ -31,8 +34,6 @@ import { PrivateBlockContext } from '../block-list/private-block-context';
*/
export { useBlockEditContext };

const BlockEditWithBindings = withBlockBindingSupport( Edit );

export default function BlockEdit( {
mayDisplayControls,
mayDisplayParentControls,
Expand All @@ -55,6 +56,7 @@ export default function BlockEdit( {
hasBlockSupport( name, 'layout', false ) ||
hasBlockSupport( name, '__experimentalLayout', false );
const { originalBlockClientId } = useContext( PrivateBlockContext );
const EditComponent = canBindBlock( name ) ? BlockEditWithBindings : Edit;

return (
<BlockEditContextProvider
Expand Down Expand Up @@ -91,7 +93,7 @@ export default function BlockEdit( {
]
) }
>
<BlockEditWithBindings { ...props } />
<EditComponent { ...props } />
{ originalBlockClientId && (
<MultipleUsageWarning
originalBlockClientId={ originalBlockClientId }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function replacePatternOverrideDefaultBindings( blockName, bindings ) {
*
* @return {WPHigherOrderComponent} Higher-order component.
*/
export const withBlockBindingSupport = createHigherOrderComponent(
export const withBlockBindingsSupport = createHigherOrderComponent(
( BlockEdit ) => ( props ) => {
const registry = useRegistry();
const blockContext = useContext( BlockContext );
Expand Down

0 comments on commit b24d527

Please sign in to comment.