Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure multiple pattern blocks with the same slug each create unique blocks #50629

Merged
merged 1 commit into from
May 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions packages/block-library/src/pattern/edit.js
Original file line number Diff line number Diff line change
@@ -42,17 +42,17 @@ const PatternEdit = ( { attributes, clientId } ) => {
// because nested pattern blocks cannot be inserted if the parent block supports
// inner blocks but doesn't have blockSettings in the state.
window.queueMicrotask( () => {
// Clone blocks from the pattern before insertion to ensure they receive
// distinct client ids. See https://github.com/WordPress/gutenberg/issues/50628.
const clonedBlocks = selectedPattern.blocks.map( ( block ) =>
cloneBlock( block )
);
__unstableMarkNextChangeAsNotPersistent();
if ( syncStatus === 'partial' ) {
replaceInnerBlocks(
clientId,
selectedPattern.blocks.map( ( block ) =>
cloneBlock( block )
)
);
replaceInnerBlocks( clientId, clonedBlocks );
return;
}
replaceBlocks( clientId, selectedPattern.blocks );
replaceBlocks( clientId, clonedBlocks );
} );
}
}, [
8 changes: 7 additions & 1 deletion packages/block-library/src/pattern/v1/edit.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* WordPress dependencies
*/
import { cloneBlock } from '@wordpress/blocks';
import { useSelect, useDispatch } from '@wordpress/data';
import { useEffect } from '@wordpress/element';
import {
@@ -32,8 +33,13 @@ const PatternEdit = ( { attributes, clientId } ) => {
// because nested pattern blocks cannot be inserted if the parent block supports
// inner blocks but doesn't have blockSettings in the state.
window.queueMicrotask( () => {
// Clone blocks from the pattern before insertion to ensure they receive
// distinct client ids. See https://github.com/WordPress/gutenberg/issues/50628.
const clonedBlocks = selectedPattern.blocks.map( ( block ) =>
cloneBlock( block )
);
__unstableMarkNextChangeAsNotPersistent();
replaceBlocks( clientId, selectedPattern.blocks );
replaceBlocks( clientId, clonedBlocks );
} );
}
}, [