-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Ensure multiple pattern blocks with the same slug each create unique blocks #50629
Conversation
Co-authored-by: Aaron Robertshaw <[email protected]>
Size Change: +2 B (0%) Total Size: 1.39 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quick fix for this @talldan 👍
It tests well for me when following the test instructions and the code changes look good.
I did hit one issue though when the "Test the Pattern block enhancements" Gutenberg experiment was turned on. Pasting multiple pattern instances into the code editor resulted in some block validation errors.
This might be better explored in a separate follow-up as it does appear related to the experiment's partially synced patterns. With the experiment off and only using the standard pattern attributes, I couldn't reproduce the error.
False alarm.
I copied and pasted the pattern markup from #50533 which left out the closing /
at the end of the comment delimiter. With the correct pattern markup, I can no longer replicate the issue.
Fixes #50629
What?
If multiple pattern blocks are inserted that reference the same slug, they can cause weird issue with blocks selections and updates. 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.
This PR fixes the issue.
Kudos to @aaronrobertshaw for suggesting the fix, and @glendaviesnz for partially implementing it in #50533
How?
Clone the blocks prior to insertion.
Testing Instructions
<!-- wp:pattern {"slug":"twentytwentythree/cta"} /-->
in multiple timesExpected: The pattern content should be separate individual content. The block toolbar has normal icon buttons
In trunk: Each instance of that button is selected and updated at the same time. The block toolbar has duplicate icon buttons.
Screenshots or screencast
Before
Kapture.2023-05-15.at.14.14.59.mp4
After
Kapture.2023-05-15.at.14.31.29.mp4