-
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
Block Styles: Ensure unique classname generation for variations #64511
Block Styles: Ensure unique classname generation for variations #64511
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Flaky tests detected in 9065b90. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/10389961399
|
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.
✅ Unique ids appear for style variations inside multiple patterns on the frontend
✅ Unique style variations rules are being generated for global styles on the frontend, e.g., :root :where(.wp-block-group.is-style-section-a--17)
…Press#64511) * Block Styles: Ensure unique classname generation for variations * Add backport changelog Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org> Co-authored-by: ramonjd <ramonopoly@git.wordpress.org> Co-authored-by: carolinan <poena@git.wordpress.org> Co-authored-by: asafm7 <asafm7@git.wordpress.org>
Fixes: #64422
What?
Simplifies block style variation class name generation to ensure unique class.
Why?
Avoids potential for non-unique class names and conflicting styles when exact copies of a block are inserted via a repeated pattern.
Background
Originally the block style variation block support followed the same approach as styles generated by the elements block support. This entailed needing to generate a predictable classname in two separate filters ruling out the prior use of
wp_unique_id
.The recent changes to these supports, such that their styles and class are generated in a single filter, mean the generated classname no longer needs to be a hash based off the block's attributes. Not only does this make the classname simpler and shorter but it also avoids the issue flagged in #64422 where exact copies of a block inserted via patterns result in the same ID and potentially conflicting styles.
How?
Replace the hashing of block attributes in the block style variation classnames with a call to
wp_unique_id
.Testing Instructions
Confirm unique classnames on frontend
is-style-outline-
. You should find CSS with three styles matching that pattern however they should now all be unique.Ensure no regressions for block style variations on the frontend
Example block style variation theme.json partial (place under `/styles`)
Screenshots or screencast
Simple unique classnames for exact copies of blocks
Block Style Variations still working
Screen.Recording.2024-08-14.at.9.24.28.PM.mp4