Skip to content

Commit f20e9b5

Browse files
committed
fix: do a preorder traversal to ensure parent is processed first
1 parent f277554 commit f20e9b5

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/block/design-library/edit.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,17 @@ const createBlockWithAttributes = ( blockName, attributes, innerBlocks, design )
3838
// Recursively substitute core blocks to disabled Stackable blocks
3939
const traverseBlocksAndSubstitute = blocks => {
4040
return blocks.map( block => {
41-
if ( block[ 2 ] && block[ 2 ].length > 0 ) {
42-
block[ 2 ] = traverseBlocksAndSubstitute( block[ 2 ] )
43-
}
41+
let isDisabled = true
4442

4543
// Check if the new substituted block is still disabled
46-
while ( block[ 0 ] in disabledBlocks && disabledBlocks[ block[ 0 ] ] === BLOCK_STATE.DISABLED ) {
44+
while ( isDisabled ) {
4745
block = substituteCoreIfDisabled( ...block, substitutionRules )
46+
isDisabled = block[ 0 ] in disabledBlocks && disabledBlocks[ block[ 0 ] ] === BLOCK_STATE.DISABLED
47+
}
48+
49+
// Do a preorder traversal by subsituting first before traversing
50+
if ( block[ 2 ] && block[ 2 ].length > 0 ) {
51+
block[ 2 ] = traverseBlocksAndSubstitute( block[ 2 ] )
4852
}
4953

5054
if ( ! Array.isArray( block[ 2 ] ) ) {

0 commit comments

Comments
 (0)