-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Backport: Caching of global styles for blocks from core #66349
Backport: Caching of global styles for blocks from core #66349
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. |
I've discussed the difficulties in backporting the unit tests from WordPress/wordpress-develop#6879 with @ramonjd and @andrewserong. The current thinking is that the time investment in setting up Gutenberg to be able to properly test this functionality isn't worth it with the coverage already in core. If others have better ideas or want to take a run at these tests as a follow-up, that's definitely an option. For the time being though, the main priority is to get Gutenberg and Core's code in sync. This PR does that so I propose to move forward with it as is. |
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.
✅ Code matches Core patch
✅ Cache is used when set and get_styles_for_block
is not hit
✅ Cache is updated when block styles change
✅ Cache isn't used when WP_DEVELOPMENT_MODE === theme
) Co-authored-by: aaronrobertshaw <[email protected]> Co-authored-by: ramonjd <[email protected]>
Backports: WordPress/wordpress-develop#6879
What?
Brings core changes adding transient caching to global styles for blocks to Gutenberg.
Why?
Performance and parity.
How?
Update
gutenberg_add_global_styles_for_blocks
in line with core'swp_add_global_styles_for_blocks
.Unit tests or lack thereof
The core tests currently rely on the
wp_get_development_mode
function's ability to fudge theWP_DEVELOPMENT_MODE
based onWP_RUN_CORE_TESTS
and a global variable that is set. Gutenberg doesn't have this capability which impedes efforts to backport all of core's tests in this area. It likely explains why Gutenberg doesn't have its own test coverage forgutenberg_add_global_styles_for_blocks
.After some digging, it doesn't appear that the time investment required to make these tests all work in Gutenberg is worth it. At best, it could be a follow-up if desired.
Testing Instructions
wp_add_global_styles_for_blocks
wordpress-develop#6879Debugging snippet
WP_DEBUG
andWP_DEBUG_LOG
are enabled in your envdebug.log
file (usually inwp-content/debug.log
by default):tail -f wp-content/debug.log
wp_styles_for_blocks
.WP_DEVELOPMENT_MODE
totheme
e.g.wp config set WP_DEVELOPMENT_MODE "theme" --allow-root
Screen.Recording.2024-10-23.at.3.57.32.pm.mp4