-
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
Section Styles: improve performance and conceptual consistency #62712
Conversation
I had to time box testing today, but can carry on later. I went through the steps outlined in #57908, taking into account the move to Block style variation JSON files under
|
Flaky tests detected in 9d8cf0e. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/9609518843
|
The preview of the styles doesn't seem to be working at first glance. Once I hit apply they seem to. I'll need to dig into that one. |
Replication steps for the Global Styles revisions issue:
Screen.Recording.2024-06-21.at.8.53.09.PM.mp4 |
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. |
Prepared backport at WordPress/wordpress-develop#6873 to gauge performance impact. |
I spun up a PR for Assembler (a theme I'm using to test this extensively) to align with this proposal. |
One change I noted is that the generated class is exclusively defined by the For example, this results in a class of While previously, it would have resulted in |
I suppose I could set slug independently as well. |
As far as I can tell this has changed at all. In both I also checked prior to each of the following PR commits
I went all the way back to the introduction of the feature in: It behaved the same at each point for me. With no Is it possible this was a misconception rather than an actual regression? |
return $theme_json; | ||
} | ||
|
||
$registered_styles = WP_Block_Styles_Registry::get_instance()->get_all_registered(); |
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.
It doesn't appear that core block type variations (e.g. Button outline) get registered in the block styles registry.
We might be able to loop registered block types and check their styles
property similar to what happens when determining valid variations for sanitization etc.
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.
Perhaps a better option would be to move the call to unwrap_shared_block_style_variations
to after the collection of $valid_variations
, then pass those as a new param. They should then contain both the core block styles as well as any registered in the WP_Block_Styles_Registry
.
What do you think?
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.
In the interests of saving time, I've pushed a commit that I think does the job: bc758fc.
a070981
to
bc758fc
Compare
I think I've got an explanation for this one now. Since the section styles feature was introduced, if a theme.json partial had a This fallback to the filename is still in place, so I'm confident there's been no regression in this regard. |
In the current version of the Assembler theme, where I'm testing this, I have "Style 1" visible labels, while using "section-1" formatting for the action variations. I don't think this is a regression, but a difference in how it works currently in trunk (whether that's intended or not). If a combination of using |
That's the catch though, for me, it works the same as on When the theme.json partials are parsed, if it doesn't have a The only recent change around this functionality was introducing support for the If there is a difference I haven't been able to replicate it, nor see it in code.
👍 That's the main thing I guess. If you're happy, I'm happy. |
Passing const globalStyles = toStyles(
updatedConfig,
blockSelectors,
hasBlockGapSupport,
hasFallbackGapSupport,
disableLayoutStyles,
options?.disableRootPadding,
{
variationStyles: true,
}
); gutenberg/packages/block-editor/src/components/global-styles/use-global-styles-output.js Lines 1366 to 1373 in bc758fc
The only question I have is whether I have a PR with the change over here: |
There might be a catch with simply passing the Passing that option should appear to work for simple uses of variations but would likely fall short when variations are applied in a nested fashion. For example, a light section that contains a dark section, then another light section within the dark one. I'll take a look at #62768 later today and double check what I've said. Thanks for putting together that fix so quickly 🚀 Update: Unfortunately, I could confirm my hunch was correct. More details here: #62768 (review) |
Thanks for the testing @andrewserong 👍 I've given this one another round of testing and I didn't notice any issues either. The extra unit tests around merging data give a nice bump in confidence as well. A rough demo video, done after testing, has been added to the PR description for good measure. |
While testing the backport for these changes I noticed that the theme style variation based definitions of block style variations are not being applied. I believe this is due to a couple of duotone filters in Gutenberg which trigger registration of block style variations from theme.json partials before the variations endpoint in the global styles controller is executed. I've updated the test instructions to include toggling these duotone filters off. diff --git a/lib/block-supports/duotone.php b/lib/block-supports/duotone.php
index 98791fe05c..df8aa39414 100644
--- a/lib/block-supports/duotone.php
+++ b/lib/block-supports/duotone.php
@@ -18,8 +18,8 @@ if ( class_exists( 'WP_Duotone' ) ) {
remove_action( 'wp_loaded', array( 'WP_Duotone', 'set_global_styles_presets' ) );
remove_action( 'wp_loaded', array( 'WP_Duotone', 'set_global_style_block_names' ) );
}
-add_action( 'wp_loaded', array( 'WP_Duotone_Gutenberg', 'set_global_styles_presets' ), 10 );
-add_action( 'wp_loaded', array( 'WP_Duotone_Gutenberg', 'set_global_style_block_names' ), 10 );
+// add_action( 'wp_loaded', array( 'WP_Duotone_Gutenberg', 'set_global_styles_presets' ), 10 );
+// add_action( 'wp_loaded', array( 'WP_Duotone_Gutenberg', 'set_global_style_block_names' ), 10 );
// Add classnames to blocks using duotone support.
if ( function_exists( 'wp_render_duotone_support' ) ) {
|
The fix for the issue noted above is to ensure the block style variations from partials were registered before the theme style variations are retrieved in the rest api endpoint. I've tested and confirmed this fix is working while the duotone filters are disabled. Screen.Recording.2024-06-24.at.6.02.33.PM.mp4 |
I gave this some testing: tried things randomly, but also the core flows (layers override each other, users can update variations, etc.). The direction is future-proof according to #62686 and this approach removes any concerns about backwards compatibility. It also improves performance as per the core PR's tests. |
There's a couple of playground failures. They are unrelated to this PR and happen in |
Corresponding core PR has been merged as well WordPress/wordpress-develop#6873 I was told we no longer need the label, as we are now only using it for tracking PRs that need package updates (we use the backport-changelog to cherry-pick the changes to the corresponding gutenberg branch). |
This moves section styles within global style variations to the `styles.variations` property. It also removes the `blockTypes` definitions for each style variation. See: WordPress/gutenberg#62712
Related:
What?
Remains unchanged: the block style variations (JSON files within
styles/
with ablockTypes
key).Changes to the primary theme.json and theme style variations (JSON files within
styles/
without ablockTypes
) key :styles.blocks.variations
tostyles.variations
.blockTypes
fromstyles.variations
.Other changes:
wp_theme_json_data_*
filters to merge the data, uses the WP_Theme_JSON_Resolver and WP_Theme_JSON classes, as per #6868.Why?
styles.blocks.blockType.variations
) are higher priority than top-level variations (styles.variations
)Testing Instructions
register_block_style
/styles
directory includingblockTypes
styles.variations
register_block_style
or a theme.json partial as wellregister_block_style
, theme.json partials, or in core block typesstyles
property such as Button's Outline style)`register_block_style` Example
Theme.json Partial Example
Theme Style Variation Example (`styles.variations`)
Demo
Screen.Recording.2024-06-24.at.2.29.21.PM.mp4