Skip to content

Commit

Permalink
Pattern: Add getBlockRootClientId call (#53206)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewserong committed Aug 1, 2023
1 parent 5efce0e commit 09d26f8
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

1 comment on commit 09d26f8

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 09d26f8.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5722908720
📝 Reported issues:

Please sign in to comment.