@@ -32,7 +32,7 @@ import {
3232 Transform ,
3333} from '~stackable/block-components'
3434import {
35- useBlockAttributesContext , useBlockContext , useBlockSetAttributesContext ,
35+ useBlockAttributesContext , useBlockSetAttributesContext ,
3636} from '~stackable/hooks'
3737import {
3838 withBlockAttributeContext , withBlockWrapperIsHovered , withQueryLoopContext ,
@@ -46,7 +46,7 @@ import variations, { defaultIcon } from './variations'
4646/**
4747 * WordPress dependencies
4848 */
49- import { InnerBlocks } from '@wordpress/block-editor'
49+ import { InnerBlocks , useBlockEditContext } from '@wordpress/block-editor'
5050import { __ } from '@wordpress/i18n'
5151import { compose } from '@wordpress/compose'
5252import { useSelect } from '@wordpress/data'
@@ -64,7 +64,12 @@ const Edit = props => {
6464 } = props
6565
6666 const [ isOpen , setIsOpen ] = useState ( props . attributes . startOpen )
67- const { hasInnerBlocks } = useBlockContext ( )
67+ const { hasInnerBlocks } = useSelect ( select => {
68+ const { getBlockOrder } = select ( 'core/block-editor' )
69+ return {
70+ hasInnerBlocks : getBlockOrder ( clientId ) . length > 0 ,
71+ }
72+ } , [ clientId ] )
6873 const [ hasInitClickHandler , setHasInitClickHandler ] = useState ( false )
6974 const { getEditorDom } = useSelect ( 'stackable/editor-dom' )
7075
@@ -215,8 +220,15 @@ addFilter( 'stackable.block-component.icon.after', 'stackable/blockquote', outpu
215220 const icon2 = useBlockAttributesContext ( attributes => attributes . icon2 )
216221 const setAttributes = useBlockSetAttributesContext ( )
217222
218- const { parentTree } = useBlockContext ( )
219- const { getBlock } = useSelect ( 'core/block-editor' )
223+ const { clientId } = useBlockEditContext ( )
224+ const { parentTree, getBlock } = useSelect ( select => {
225+ const { getBlock, getBlockParents } = select ( 'core/block-editor' )
226+ const parentTree = getBlockParents ( clientId ) . map ( parentClientId => ( { clientId : parentClientId , name : getBlock ( parentClientId ) . name } ) )
227+ return {
228+ getBlock,
229+ parentTree,
230+ }
231+ } , [ clientId ] )
220232 const { getActiveBlockVariation } = useSelect ( 'core/blocks' )
221233
222234 const accordionBlock = findLast ( parentTree , pt => pt . name === 'stackable/accordion' )
@@ -259,8 +271,15 @@ addFilter( 'stackable.block-default-styles.use-saved-style', 'stackable/icon-lab
259271
260272// Return default icon for accordion
261273addFilter ( 'stackable.block-component.icon.default' , 'stackable/accordion' , starIcon => {
262- const { parentTree } = useBlockContext ( )
263- const { getBlock } = useSelect ( 'core/block-editor' )
274+ const { clientId } = useBlockEditContext ( )
275+ const { parentTree, getBlock } = useSelect ( select => {
276+ const { getBlock, getBlockParents } = select ( 'core/block-editor' )
277+ const parentTree = getBlockParents ( clientId ) . map ( parentClientId => ( { clientId : parentClientId , name : getBlock ( parentClientId ) . name } ) )
278+ return {
279+ getBlock,
280+ parentTree,
281+ }
282+ } , [ clientId ] )
264283 const { getActiveBlockVariation } = useSelect ( 'core/blocks' )
265284
266285 const accordionBlock = findLast ( parentTree , pt => pt . name === 'stackable/accordion' )
0 commit comments