Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple pattern blocks with the same slug causes duplicate block selection/updates #50628

Closed
talldan opened this issue May 15, 2023 Discussed in #50554 · 1 comment
Closed
Assignees
Labels
[Block] Pattern Affects the Patterns Block [Type] Bug An existing feature does not function as intended

Comments

@talldan
Copy link
Contributor

talldan commented May 15, 2023

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

  1. Use twenty twenty three
  2. Open an editor and switch to code editor mode
  3. Paste <!-- wp:pattern {"slug":"twentytwentythree/cta"} /--> in multiple times
  4. Switch back to visual mode and try editing the text of the 'Get in touch' button

Actual: 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 named mynamespace/glossary-list which includes 4 instances of <!-- wp:pattern {"slug":"mynamespace/glossary-group"} /-->. When I insert the mynamespace/glossary-list, the 4 instances of mynamespace/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?

@talldan talldan added [Type] Bug An existing feature does not function as intended [Block] Pattern Affects the Patterns Block labels May 15, 2023
@talldan talldan self-assigned this May 15, 2023
@talldan
Copy link
Contributor Author

talldan commented May 16, 2023

Fixed by #50629

@talldan talldan closed this as completed May 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Pattern Affects the Patterns Block [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

1 participant