Skip to content

Commit fc7a096

Browse files
committed
Remove the block when deleting a shared block
When deleting a shared block, any blocks in the page that reference that shared block should be removed from the post.
1 parent ea710ca commit fc7a096

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

editor/store/effects.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
switchToBlockType,
1414
createBlock,
1515
serialize,
16+
isSharedBlock,
1617
getDefaultBlockForPostFormat,
1718
doBlocksMatchTemplate,
1819
synchronizeBlocksWithTemplate,
@@ -39,6 +40,7 @@ import {
3940
removeNotice,
4041
saveSharedBlock,
4142
insertBlock,
43+
removeBlocks,
4244
selectBlock,
4345
removeBlock,
4446
resetBlocks,
@@ -545,7 +547,13 @@ export default {
545547
}
546548

547549
const { id } = action;
548-
const { dispatch } = store;
550+
const { getState, dispatch } = store;
551+
552+
// Remove any blocks that reference this shared block
553+
const allBlocks = getBlocks( getState() );
554+
const associatedBlocks = allBlocks.filter( ( block ) => isSharedBlock( block ) && block.attributes.ref === id );
555+
const associatedBlockUids = associatedBlocks.map( ( block ) => block.uid );
556+
dispatch( removeBlocks( associatedBlockUids ) );
549557

550558
const transactionId = uniqueId();
551559

0 commit comments

Comments
 (0)