diff --git a/packages/block-editor/src/components/block-controls/slot.js b/packages/block-editor/src/components/block-controls/slot.js index c8cb65848e9f77..65a3151552c9c3 100644 --- a/packages/block-editor/src/components/block-controls/slot.js +++ b/packages/block-editor/src/components/block-controls/slot.js @@ -7,6 +7,7 @@ import { ToolbarGroup, __experimentalUseSlotFills as useSlotFills, } from '@wordpress/components'; +import warning from '@wordpress/warning'; /** * Internal dependencies @@ -15,11 +16,14 @@ import groups from './groups'; export default function BlockControlsSlot( { group = 'default', ...props } ) { const accessibleToolbarState = useContext( ToolbarContext ); - const Slot = groups[ group ].Slot; - const fills = useSlotFills( Slot.__unstableName ); - const hasFills = Boolean( fills && fills.length ); + const Slot = groups[ group ]?.Slot; + const fills = useSlotFills( Slot?.__unstableName ); + if ( ! Slot ) { + warning( `Unknown BlockControls group "${ group }" provided.` ); + return null; + } - if ( ! hasFills ) { + if ( ! fills?.length ) { return null; } diff --git a/packages/block-editor/src/components/block-controls/slot.native.js b/packages/block-editor/src/components/block-controls/slot.native.js index 7ec46a8ef2251c..5919972aef202b 100644 --- a/packages/block-editor/src/components/block-controls/slot.native.js +++ b/packages/block-editor/src/components/block-controls/slot.native.js @@ -6,6 +6,7 @@ import { __experimentalToolbarContext as ToolbarContext, ToolbarGroup, } from '@wordpress/components'; +import warning from '@wordpress/warning'; /** * Internal dependencies @@ -14,7 +15,11 @@ import groups from './groups'; export default function BlockControlsSlot( { group = 'default', ...props } ) { const accessibleToolbarState = useContext( ToolbarContext ); - const Slot = groups[ group ].Slot; + const Slot = groups[ group ]?.Slot; + if ( ! Slot ) { + warning( `Unknown BlockControls group "${ group }" provided.` ); + return null; + } if ( group === 'default' ) { return ; diff --git a/packages/block-editor/src/components/inspector-controls/fill.js b/packages/block-editor/src/components/inspector-controls/fill.js index b93fb2acc4749a..d33691c9b704aa 100644 --- a/packages/block-editor/src/components/inspector-controls/fill.js +++ b/packages/block-editor/src/components/inspector-controls/fill.js @@ -41,7 +41,7 @@ export default function InspectorControlsFill( { const isDisplayed = useDisplayBlockControls(); const Fill = groups[ group ]?.Fill; if ( ! Fill ) { - warning( `Unknown InspectorControl group "${ group }" provided.` ); + warning( `Unknown InspectorControls group "${ group }" provided.` ); return null; } if ( ! isDisplayed ) { diff --git a/packages/block-editor/src/components/inspector-controls/fill.native.js b/packages/block-editor/src/components/inspector-controls/fill.native.js index 37c084806da689..d38d865cd15cc0 100644 --- a/packages/block-editor/src/components/inspector-controls/fill.native.js +++ b/packages/block-editor/src/components/inspector-controls/fill.native.js @@ -39,7 +39,7 @@ export default function InspectorControlsFill( { const Fill = groups[ group ]?.Fill; if ( ! Fill ) { - warning( `Unknown InspectorControl group "${ group }" provided.` ); + warning( `Unknown InspectorControls group "${ group }" provided.` ); return null; } if ( ! isDisplayed ) { diff --git a/packages/block-editor/src/components/inspector-controls/slot.js b/packages/block-editor/src/components/inspector-controls/slot.js index 883421cacec233..3687644b21b4da 100644 --- a/packages/block-editor/src/components/inspector-controls/slot.js +++ b/packages/block-editor/src/components/inspector-controls/slot.js @@ -1,10 +1,7 @@ /** * WordPress dependencies */ -import { - __experimentalUseSlot as useSlot, - __experimentalUseSlotFills as useSlotFills, -} from '@wordpress/components'; +import { __experimentalUseSlotFills as useSlotFills } from '@wordpress/components'; import warning from '@wordpress/warning'; import deprecated from '@wordpress/deprecated'; @@ -33,15 +30,13 @@ export default function InspectorControlsSlot( { group = __experimentalGroup; } const Slot = groups[ group ]?.Slot; - const slot = useSlot( Slot?.__unstableName ); const fills = useSlotFills( Slot?.__unstableName ); - if ( ! Slot || ! slot ) { - warning( `Unknown InspectorControl group "${ group }" provided.` ); + if ( ! Slot ) { + warning( `Unknown InspectorControls group "${ group }" provided.` ); return null; } - const hasFills = Boolean( fills && fills.length ); - if ( ! hasFills ) { + if ( ! fills?.length ) { return null; } diff --git a/packages/block-editor/src/components/inspector-controls/slot.native.js b/packages/block-editor/src/components/inspector-controls/slot.native.js index 4354e08165d914..e8917a6003b47d 100644 --- a/packages/block-editor/src/components/inspector-controls/slot.native.js +++ b/packages/block-editor/src/components/inspector-controls/slot.native.js @@ -27,7 +27,7 @@ export default function InspectorControlsSlot( { } const Slot = groups[ group ]?.Slot; if ( ! Slot ) { - warning( `Unknown InspectorControl group "${ group }" provided.` ); + warning( `Unknown InspectorControls group "${ group }" provided.` ); return null; }