Skip to content
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
9 changes: 6 additions & 3 deletions packages/block-library/src/pattern/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
*/
import { unlock } from '../lock-unlock';

const PatternEdit = ( { attributes, clientId, rootClientId } ) => {
const PatternEdit = ( { attributes, clientId } ) => {
const selectedPattern = useSelect(
( select ) =>
select( blockEditorStore ).__experimentalGetParsedPattern(
Expand All @@ -26,7 +26,9 @@ const PatternEdit = ( { attributes, clientId, rootClientId } ) => {
const { replaceBlocks, __unstableMarkNextChangeAsNotPersistent } =
useDispatch( blockEditorStore );
const { setBlockEditingMode } = unlock( useDispatch( blockEditorStore ) );
const { getBlockEditingMode } = unlock( useSelect( blockEditorStore ) );
const { getBlockRootClientId, getBlockEditingMode } = unlock(
useSelect( blockEditorStore )
);

// Run this effect when the component loads.
// This adds the Pattern's contents to the post.
Expand All @@ -40,6 +42,7 @@ const PatternEdit = ( { attributes, clientId, rootClientId } ) => {
// because nested pattern blocks cannot be inserted if the parent block supports
// inner blocks but doesn't have blockSettings in the state.
window.queueMicrotask( () => {
const rootClientId = getBlockRootClientId( clientId );
// 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 ) =>
Expand All @@ -58,13 +61,13 @@ const PatternEdit = ( { attributes, clientId, rootClientId } ) => {
} );
}
}, [
rootClientId,
clientId,
selectedPattern?.blocks,
__unstableMarkNextChangeAsNotPersistent,
replaceBlocks,
getBlockEditingMode,
setBlockEditingMode,
getBlockRootClientId,
] );

const props = useBlockProps();
Expand Down