Skip to content

Commit

Permalink
Pattern: Add getBlockRootClientId call
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewserong committed Aug 1, 2023
1 parent 5efce0e commit e133190
Showing 1 changed file with 6 additions and 3 deletions.
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

0 comments on commit e133190

Please sign in to comment.