From e133190232edc420f84c28336d002b2ba24caf3d Mon Sep 17 00:00:00 2001 From: Andrew Serong <14988353+andrewserong@users.noreply.github.com> Date: Tue, 1 Aug 2023 14:14:36 +1000 Subject: [PATCH] Pattern: Add getBlockRootClientId call --- packages/block-library/src/pattern/edit.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/pattern/edit.js b/packages/block-library/src/pattern/edit.js index 824960f90b379..bf5b84eeb0296 100644 --- a/packages/block-library/src/pattern/edit.js +++ b/packages/block-library/src/pattern/edit.js @@ -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( @@ -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. @@ -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 ) => @@ -58,13 +61,13 @@ const PatternEdit = ( { attributes, clientId, rootClientId } ) => { } ); } }, [ - rootClientId, clientId, selectedPattern?.blocks, __unstableMarkNextChangeAsNotPersistent, replaceBlocks, getBlockEditingMode, setBlockEditingMode, + getBlockRootClientId, ] ); const props = useBlockProps();