Skip to content

Commit

Permalink
Fix the issue with missing context established by sources
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Dec 3, 2024
1 parent 02805fc commit 5365702
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
12 changes: 10 additions & 2 deletions packages/block-editor/src/components/block-edit/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { useContext, useMemo } from '@wordpress/element';
* Internal dependencies
*/
import BlockContext from '../block-context';
import { withBlockBindingsSupport } from './with-block-bindings-support';
import { canBindBlock } from '../../utils/block-bindings';

/**
* Default value used for blocks which do not define their own context needs,
Expand Down Expand Up @@ -47,6 +49,8 @@ const Edit = ( props ) => {

const EditWithFilters = withFilters( 'editor.BlockEdit' )( Edit );

const EditWithFiltersAndBindings = withBlockBindingsSupport( EditWithFilters );

const EditWithGeneratedProps = ( props ) => {
const { attributes = {}, name } = props;
const blockType = getBlockType( name );
Expand All @@ -67,8 +71,12 @@ const EditWithGeneratedProps = ( props ) => {
return null;
}

const EditComponent = canBindBlock( name )
? EditWithFiltersAndBindings
: EditWithFilters;

if ( blockType.apiVersion > 1 ) {
return <EditWithFilters { ...props } context={ context } />;
return <EditComponent { ...props } context={ context } />;
}

// Generate a class name for the block's editable form.
Expand All @@ -82,7 +90,7 @@ const EditWithGeneratedProps = ( props ) => {
);

return (
<EditWithFilters
<EditComponent
{ ...props }
context={ context }
className={ className }
Expand Down
7 changes: 1 addition & 6 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,6 @@ import { hasBlockSupport } from '@wordpress/blocks';
* Internal dependencies
*/
import Edit from './edit';
import { withBlockBindingsSupport } from './with-block-bindings-support';
import {
BlockEditContextProvider,
useBlockEditContext,
Expand All @@ -20,9 +19,6 @@ 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 Down Expand Up @@ -56,7 +52,6 @@ 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 @@ -93,7 +88,7 @@ export default function BlockEdit( {
]
) }
>
<EditComponent { ...props } />
<Edit { ...props } />
{ originalBlockClientId && (
<MultipleUsageWarning
originalBlockClientId={ originalBlockClientId }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,12 @@ export const withBlockBindingsSupport = createHigherOrderComponent(
);

return (
<>
<BlockEdit
{ ...props }
attributes={ { ...props.attributes, ...boundAttributes } }
setAttributes={ _setAttributes }
context={ { ...context, ...updatedContext } }
/>
</>
<BlockEdit
{ ...props }
attributes={ { ...props.attributes, ...boundAttributes } }
setAttributes={ _setAttributes }
context={ { ...context, ...updatedContext } }
/>
);
},
'withBlockBindingSupport'
Expand Down

0 comments on commit 5365702

Please sign in to comment.