-
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
Elements: Merge element style and classname generation to single filter #59535
Conversation
Making the class name and style generation occur in the same filter allows the same block data to be used to generate the class regardless of if that data is filtered further elsewhere. Note: There's still possibility of class name conflict but greatly reduced.
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. |
This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress. If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged. If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack. Thank you! ❤️ View changed files❔ lib/block-supports/elements.php ❔ phpunit/block-supports/elements-test.php |
The test failures are related to the changes in this PR. I'm working on fixes for them now. |
*/ | ||
function gutenberg_render_elements_support_styles( $pre_render, $block ) { |
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.
wp_render_elements_support_styles has been a public function since WP 6.0.
I searched on wpdirectory.net and there doesn't appear to be any usages, but I'm wondering if we should formally deprecate this one to make sure?
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.
I'm not 100% sure on this one. These filters weren't designed to be reused. They're also not publicly documented as part of our API, and only really useful as a filter for this specific use case.
Given that, I'm leaning towards handling any deprecation requirements in the core backport.
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.
I'd recommend handling it consistently in Gutenberg if the intent is to convert the parameter to $deprecated
in Core.
It's the kind of thing that can be easily missed when merging to the wp-dev repo so it would be good to avoid any risk.
It's also hooked on to render_block_data
with 10, 2
so may end up throwing an error. I'm unable to see if the filter render_block_data
has changed in GB but it's pretty old so is probably only in WP-Dev now days.
} | ||
|
||
/** | ||
* Ensure the elements block support class name generated and added to |
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.
This seems to be a bug; I'd expect it to not be necessary to add the attributes manually to $block_content
. It might be this issue resurfacing. I was meaning to fix it at the time and then forgot all about it 😅
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.
My inclination was that it was due to the block being static and the markup having been generated at the point it was saved rather than render.
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.
This looks like a good follow-up fix to me, thanks for digging in @aaronrobertshaw!
✅ Tested that #59462 is still resolved
✅ Nested link styles are now working correctly
There'll likely be a little bit of stuff to deal with in the backport to core process (deprecating the existing function, swapping null coalescing operators for ternaries?), but the approach here looks good to me, and I like the idea of injecting the classname into the attribute, and then ensuring it's output in the render callback/filter.
LGTM! ✨
Manual testing works as described for me too 🚀 |
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.
Follow up re: Raymon's comment on back-compat.
And while I was here figured I'd not the coding standards thing.
Sorry for the late notice, as someone who primarily track wp-dev it's easier to track GB commits rather than all the PRs.
*/ | ||
function gutenberg_render_elements_support_styles( $pre_render, $block ) { |
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.
I'd recommend handling it consistently in Gutenberg if the intent is to convert the parameter to $deprecated
in Core.
It's the kind of thing that can be easily missed when merging to the wp-dev repo so it would be good to avoid any risk.
It's also hooked on to render_block_data
with 10, 2
so may end up throwing an error. I'm unable to see if the filter render_block_data
has changed in GB but it's pretty old so is probably only in WP-Dev now days.
// To ensure a consistent elements class name it is generated within a | ||
// `render_block_data` filter and stored in the `className` attribute. | ||
// As a result the block data needs to be passed through the same | ||
// function for this test. |
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.
/*
* Multiline comments
* use this format
*/
Per WP Coding standards for PHP and JS. https://developer.wordpress.org/coding-standards/inline-documentation-standards/php/#5-inline-comments
A common gotcha is to start wiht /**
-- please don't as that's used by parsers looking for docblocks
// Ensure the elements class name set in render_block_data filter is applied in markup. | ||
// See `gutenberg_render_elements_support_styles`. |
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.
As above re comment formatting.
I just cherry-picked this PR to the release/17.8 branch to get it included in the next release: 374f652 |
@peterwilsoncc this is just a filter that was added to the |
@tellthemachines typically we deprecate even the private functions as historically extenders have used functions & classes whether they're marked public, private or internal. List Table classes prior to r54378 are the poster child for this but there's other common examples too. I'm trying to understand how it hooks on to |
Thanks for the feedback @peterwilsoncc 👍 I'll put together two PRs shortly:
If I follow the question correctly, it isn't clear how the element block supports use to work versus the latest approach in this PR? Previously, the elements block supports were implemented in two parts:
I believe this was originally done this way so that the order the CSS was generated resulted in the correct cascade. If the CSS generation happened in the original To generate a consistent class name between those two filters ( That brings us to this PR and the current approach:
I hope that helps clarify the situation some 🤞 If not, I'll get a couple of PRs up addressing the feedback and they might shed further light on the matter. Thanks again for the feedback and help! |
A very quick and rough draft for updating Gutenberg as discussed above can be found in #59538. I might not be able to iterate on that PR and a backport until next week however. |
Even more rough draft for a backport is up in WordPress/wordpress-develop#6214. As noted on both the PRs mentioned here, I will have very limited bandwidth until next week to push them across the line. If there is any urgency to land these and someone would like to pick them up, please do! 🙏 |
@aaronrobertshaw Thanks for handling the Backport. I wasn't sure whether this is headed for WP 6.5. Could you confirm? |
The changes from this PR and #59538 are combined in a single backport available in WordPress/wordpress-develop#6214. |
Addresses: #59462
Related: #59533
What?
This is an alternate approach to fixing #59462 and the further issue noted on the original fix in #59533.
TL;DR - Prevents other filters from disrupting the element class name generation while also reducing the chance for class name conflicts.
Why?
While #59533 fixed the original issue it introduced further albeit reduced issues.
How?
pre_render_block
torender_block_data
render_block_data
filter, generate and store both the elements styles and class namerender_block
filter to double-check if an elements class name has been added to the block attributes then add it to the block contentTesting Instructions
Confirm #59462 is still resolved
Confirm nested applications of the same element styles work correctly:
Example block markup
Screenshots or screencast
In the before screenshot the third paragraph's link color is not applied correctly.