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

Plugin: Use bundled files for enqueuing global styles #50310

Merged
merged 6 commits into from
May 11, 2023

Conversation

Mamaduka
Copy link
Member

@Mamaduka Mamaduka commented May 4, 2023

What?

Regression after #50079 (comment)

PR adds a script loader not tied to the specific WP version to override global styles enqueued by core. The new one will use the WP_Theme_JSON classes bundled with the plugin.

Why?

Bundled WP_Theme_JSON files should provide some of the settings for global styles.

How?

Testing Instructions

#50079 (comment)

@Mamaduka Mamaduka added [Type] Regression Related to a regression in the latest release Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json labels May 4, 2023
@Mamaduka Mamaduka self-assigned this May 4, 2023
@Mamaduka
Copy link
Member Author

Mamaduka commented May 4, 2023

Hey, @oandregal

What do you think about these "permanent" overrides for settings that need to use bundled WP_Theme_JSON_*Gutenberg classes?

@gziolo gziolo added the Gutenberg Plugin Issues or PRs related to Gutenberg Plugin management related efforts label May 5, 2023
Copy link
Contributor

@tellthemachines tellthemachines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for getting this started! It not working for me yet with the testing steps I outlined in the other PR, but I think this is a good approach in general, at least while global styles and design tools are still under active development.

@Mamaduka Mamaduka force-pushed the fix/enqueue-global-styles branch from 6a605a0 to eec751a Compare May 5, 2023 05:15
@Mamaduka Mamaduka marked this pull request as ready for review May 5, 2023 05:18
@Mamaduka Mamaduka requested a review from spacedmonkey as a code owner May 5, 2023 05:18
@Mamaduka
Copy link
Member Author

Mamaduka commented May 5, 2023

@tellthemachines, I think I got all the parts ported into the new system. Overriding the styles for block editor settings was the missing piece - eec751a.

@oandregal
Copy link
Member

What do you think about these "permanent" overrides for settings that need to use bundled WP_Theme_JSON_*Gutenberg classes?

Yeah, this is annoying. As long as the underlying classes receive changes, the public API needs to point at them in the plugin.

I'd think it's best to make them "evergreen" (so they'd sit in lib/) as the private classes do. I wouldn't be against making them part of lib/compat/6.X, though it seems that this would just "move the problem to the future": once the minimum WP version for Gutenberg is 6.2 they'll be removed, so we'll run into the same issue because the private classes will still receive updates. Does that sound sensible?

@Mamaduka
Copy link
Member Author

Mamaduka commented May 5, 2023

I wouldn't be against making them part of lib/compat/6.X, though it seems that this would just "move the problem to the future"

I agree. Keeping this code in compat/wordpress- creates an "opportunity" for future regressions.

One more thing. Should I also move _gutenberg_clean_theme_json_caches into the "evergreen" files, or is there a plan to match the cache keys used by the plugin to WP?

@oandregal
Copy link
Member

One more thing. Should I also move _gutenberg_clean_theme_json_caches into the "evergreen" files, or is there a plan to match the cache keys used by the plugin to WP?

No, they need to be different from core.

Would you be up to prepare small PRs that migrate each method separately? Otherwise, it's a big PR with a lot of changes that are difficult to match to each other. If it's just moving methods around, things are easy to spot.

@Mamaduka
Copy link
Member Author

Mamaduka commented May 5, 2023

Would you be up to prepare small PRs that migrate each method separately?

I would, but all the changes in this PR are needed to fix the regression reported by @tellthemachines - #50079 (comment).

I've not touched the methods; I just moved them. The changes that could use a detailed review are concentrated in lib/block-editor-settings.php and lib/script-loader.php files.


/*
* For the remaining types (presets, styles), we do consider origins:
if ( ! function_exists( 'wp_get_global_styles_custom_css' ) ) {
Copy link
Member

@oandregal oandregal May 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was expecting that the only change here would be to move some methods from this file to lib/get-global-styles-and-settings.php.

As far as I've checked, we should move gutenberg_get_global_styles_custom_css, gutenberg_get_global_stylesheet, gutenberg_get_global_settings, _gutenberg_clean_theme_json_caches, _gutenberg_add_non_persistent_theme_json_cache_group.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved everything besides _gutenberg_add_non_persistent_theme_json_cache_group. The cache group would be the same, so there's no need to keep that function after 6.2.

@Mamaduka
Copy link
Member Author

Mamaduka commented May 9, 2023

@oandregal, I addressed the feedback, and PR is ready for another review.

@Mamaduka Mamaduka force-pushed the fix/enqueue-global-styles branch from 0d48ea4 to f95f040 Compare May 9, 2023 17:04
@github-actions
Copy link

github-actions bot commented May 9, 2023

Flaky tests detected in f95f040.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4928503293
📝 Reported issues:

@Mamaduka
Copy link
Member Author

Hi, @tellthemachines

Did you get a chance to test the fix?

@tellthemachines
Copy link
Contributor

@Mamaduka I won't be able to do a full code review this week, but I've just tested the latest state of this branch and it's now working correctly. I checked the spacing styles within flow/constrained layouts and also the experimental grid styles, and both are as expected ✅

@Mamaduka
Copy link
Member Author

I won't be able to do a full code review this week,

Not a problem. I just want to be sure that PR fixes the regression. Thanks for testing!

Copy link
Contributor

@aaronrobertshaw aaronrobertshaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing this @Mamaduka 👍

It's always a pleasure to find a bug already has a fix up for review!

It turns out #50079 also caused the custom selectors API to be missed. This PR fixes that issue.

The code changes LGTM but it might be best to wait on a final review from @tellthemachines to make sure everything has been covered from their end.

*
* @access private
*/
function _gutenberg_clean_theme_json_caches() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been moved to lib/global-styles-and-settings.php verbatim.

@@ -17,13 +17,6 @@
* @package gutenberg
*/

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been moved to lib/global-styles-and-settings.php verbatim. The comment no longer makes sense as core already uses the proper function as a callback.

*
* @since 6.2.0
*/
function gutenberg_enqueue_global_styles_custom_css() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function and the filter has been moved to lib/script-loader.php verbatim.

*
* @return void
*/
function gutenberg_add_global_styles_for_blocks() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This brings back this function, that had been removed in #50079

*
* @return void
*/
function gutenberg_enqueue_global_styles() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This brings this function back after having being removed at #50079

*
* @since 5.9.0
*/
function gutenberg_enqueue_global_styles_css_custom_properties() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This brings back a function that I haven't seen at #50079 though it still makes sense to me.

Copy link
Member

@oandregal oandregal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested this solves the issues brought by others. The code changes make sense to me: either move things around or add back things (added comments for each function trying to document what changes).

@Mamaduka
Copy link
Member Author

Thanks, @oandregal!

I’ll merge this to fix the regressions. Happy to follow up in case I missed something.

@Mamaduka Mamaduka merged commit 0f56002 into trunk May 11, 2023
@Mamaduka Mamaduka deleted the fix/enqueue-global-styles branch May 11, 2023 16:25
@github-actions github-actions bot added this to the Gutenberg 15.9 milestone May 11, 2023
@Mamaduka
Copy link
Member Author

@fabiankaegy, the #50079 will ship with Gutenberg 15.8; I think it makes sense to cherry-pick this PR and avoid regressions in the release.

@fabiankaegy fabiankaegy added the Backport to Gutenberg RC Pull request that needs to be backported to a Gutenberg release candidate (RC) label May 12, 2023
@fabiankaegy
Copy link
Member

I just cherry-picked this PR to the release/15.8 branch to get it included in the next release: f7d2fbd

fabiankaegy pushed a commit that referenced this pull request May 12, 2023
* Plugin: Use bundled files for enqueuing global styles

* Override the '__experimentalFeatures'

* Recreate global styles for block editors

* Move global styles custom CSS handlers

* Move _gutenberg_clean_theme_json_caches

* Override global styles custom CSS properties
@fabiankaegy fabiankaegy removed the Backport to Gutenberg RC Pull request that needs to be backported to a Gutenberg release candidate (RC) label May 12, 2023
@oandregal
Copy link
Member

I've got a couple of follow-ups at #50596 and #50597.

}
}

$settings['styles'] = array_merge( $global_styles, get_block_editor_theme_styles() );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this broke duotone filters which rely on updating $settings['styles'] in the same hook. Is there a reason that this hook needs to run at PHP_INT_MAX priority?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason that this hook needs to run at PHP_INT_MAX priority?

That's what the plugin always used for block setting overrides. I guess to prevent other plugins from overriding new feature settings.

I personally don't like the use of PHP_INT_MAX; it prevents extensibility.

Can you point me to where the Duotone filters are located? Happy to help with the fix.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what the plugin always used for block setting overrides.

Ah, it just appended to the styles rather than replacing them before.

Can you point me to where the Duotone filters are located?

The duotone hook is here

add_filter( 'block_editor_settings_all', array( 'WP_Duotone_Gutenberg', 'add_editor_settings' ), 10 );

Happy to help with the fix.

Thanks! I'll probably push up a PR sometime today and add you as a reviewer. It sounds like it should be safe to lower the priority to allow for the extensibility that now comes from within the plugin.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oandregal, any thoughts on lowering the priority for the plugin overrides?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened #50760. I found and fixed a few other things when I was digging through all of the code that used the same hook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json Gutenberg Plugin Issues or PRs related to Gutenberg Plugin management related efforts [Type] Regression Related to a regression in the latest release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants