Multiple pattern blocks with the same slug causes duplicate block selection/updates #50628
Labels
[Block] Pattern
Affects the Patterns Block
[Type] Bug
An existing feature does not function as intended
Description
If multiple pattern blocks are inserted that reference the same slug, they can cause weird issue with blocks selections and update. The blocks seem 'linked'.
This is because when the pattern is inserted, it gets the block data from the
__experimentalGetParsedPattern
selector each time, and that selector provides the same client ids for the inner blocks of each pattern.A simple fix should be to
clone
the inner blocks before insertion so that they don't use the same clientIds.(Thanks to @ChrissiQ for originally reporting this in the discussion linked below)
Reproduction steps
<!-- wp:pattern {"slug":"twentytwentythree/cta"} /-->
in multiple timesActual: Each instance of that button is selected and updated at the same time. The block toolbar has duplicate icon buttons.
Expected: The pattern content should be separate individual content. The block toolbar has normal icon buttons
Video
Kapture.2023-05-15.at.14.14.59.mp4
Originally discussed in #50554
Originally posted by ChrissiQ May 12, 2023
I don't know if this is intended or not but I'm confused by it.
I created a block pattern named
mynamespace/glossary-group
. Then I created a new block pattern namedmynamespace/glossary-list
which includes 4 instances of<!-- wp:pattern {"slug":"mynamespace/glossary-group"} /-->
. When I insert themynamespace/glossary-list
, the 4 instances ofmynamespace/glossary-group
are linked. When I select one, all of them are selected. When I edit the content inside one, the content inside the others is linked.Then, once the page is saved and editor reloaded, they are no longer linked.
Is this intentional? Can I make the multiple instances of the same pattern inside a block pattern unlinked somehow?
The text was updated successfully, but these errors were encountered: