diff --git a/packages/block-editor/src/store/reducer.js b/packages/block-editor/src/store/reducer.js index b316bbeb5079e1..b851c0293c8f16 100644 --- a/packages/block-editor/src/store/reducer.js +++ b/packages/block-editor/src/store/reducer.js @@ -1604,18 +1604,17 @@ export function preferences( state = PREFERENCES_DEFAULTS, action ) { case 'REPLACE_BLOCKS': return action.blocks.reduce( ( prevState, block ) => { const { attributes, name: blockName } = block; + let id = blockName; + // If a block variation match is found change the name to be the same with the + // one that is used for block variations in the Inserter (`getItemFromVariation`). const match = select( blocksStore ).getActiveBlockVariation( blockName, attributes ); - // If a block variation match is found change the name to be the same with the - // one that is used for block variations in the Inserter (`getItemFromVariation`). - let id = match?.name - ? `${ blockName }/${ match.name }` - : blockName; - const insert = { name: id }; + if ( match?.name ) { + id += '/' + match.name; + } if ( blockName === 'core/block' ) { - insert.ref = attributes.ref; id += '/' + attributes.ref; } @@ -1628,7 +1627,6 @@ export function preferences( state = PREFERENCES_DEFAULTS, action ) { count: prevState.insertUsage[ id ] ? prevState.insertUsage[ id ].count + 1 : 1, - insert, }, }, }; diff --git a/packages/block-editor/src/store/test/reducer.js b/packages/block-editor/src/store/test/reducer.js index 67ed0ae69106d6..c06936047f8329 100644 --- a/packages/block-editor/src/store/test/reducer.js +++ b/packages/block-editor/src/store/test/reducer.js @@ -2889,7 +2889,6 @@ describe( 'state', () => { 'core/embed': { time: 123456, count: 1, - insert: { name: 'core/embed' }, }, }, } ); @@ -2900,7 +2899,6 @@ describe( 'state', () => { 'core/embed': { time: 123456, count: 1, - insert: { name: 'core/embed' }, }, }, } ), @@ -2926,12 +2924,10 @@ describe( 'state', () => { 'core/embed': { time: 123457, count: 2, - insert: { name: 'core/embed' }, }, 'core/block/123': { time: 123457, count: 1, - insert: { name: 'core/block', ref: 123 }, }, }, } ); @@ -2994,17 +2990,14 @@ describe( 'state', () => { [ orangeVariationName ]: { time: 123456, count: 1, - insert: { name: orangeVariationName }, }, [ appleVariationName ]: { time: 123456, count: 1, - insert: { name: appleVariationName }, }, [ blockWithVariations ]: { time: 123456, count: 2, - insert: { name: blockWithVariations }, }, } ), } );