Skip to content

Global styles: block background UI controls#6836

Closed
ramonjd wants to merge 6 commits intoWordPress:trunkfrom
ramonjd:add/background-global-styles-panel-for-blocks
Closed

Global styles: block background UI controls#6836
ramonjd wants to merge 6 commits intoWordPress:trunkfrom
ramonjd:add/background-global-styles-panel-for-blocks

Conversation

@ramonjd
Copy link
Copy Markdown
Member

@ramonjd ramonjd commented Jun 17, 2024

Syncing source code changes from WordPress/gutenberg#60100

Enables background images for supported blocks in global styles.

Testing

This PR adds the backend functionality only, which means the editor UI isn't yet available.

To test, define some background images for blocks. Here's an example using some of the images in src/wp-content/themes/twentytwentyfour/

{
	"$schema": "../../schemas/json/theme.json",
	"version": 3,
	"settings": {
		"appearanceTools": true
	},
	"styles": {
		"blocks": {
			"core/verse": {
				"background": {
					"backgroundImage": {
						"url": "file:./assets/images/art-gallery.webp"
					}
				}
			},
			"core/quote": {
				"background": {
					"backgroundImage": {
						"url": "file:./assets/images/building-exterior.webp"
					}
				}
			},
			"core/pullquote": {
				"background": {
					"backgroundImage": {
						"url": "file:./assets/images/hotel-facade.webp"
					}
				}
			},
			"core/post-content": {
				"background": {
					"backgroundImage": {
						"url": "file:./assets/images/windows.webp"
					}
				}
			}
		}
	}
}

Here is some test HTML to create a test post:

<!-- wp:verse {"style":{"elements":{"link":{"color":{"text":"var:preset|color|base-2"}}},"spacing":{"padding":{"top":"var:preset|spacing|60","bottom":"var:preset|spacing|60","left":"var:preset|spacing|60","right":"var:preset|spacing|60"}}},"textColor":"base-2","fontSize":"x-large"} -->
<pre class="wp-block-verse has-base-2-color has-text-color has-link-color has-x-large-font-size" style="padding-top:var(--wp--preset--spacing--60);padding-right:var(--wp--preset--spacing--60);padding-bottom:var(--wp--preset--spacing--60);padding-left:var(--wp--preset--spacing--60)">Verse</pre>
<!-- /wp:verse -->

<!-- wp:pullquote {"style":{"elements":{"link":{"color":{"text":"var:preset|color|base-2"}}}},"textColor":"base-2","fontSize":"x-large"} -->
<figure class="wp-block-pullquote has-base-2-color has-text-color has-link-color has-x-large-font-size"><blockquote><p>Pullquote</p></blockquote></figure>
<!-- /wp:pullquote -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><!-- wp:paragraph {"style":{"spacing":{"padding":{"top":"var:preset|spacing|60","bottom":"var:preset|spacing|60","left":"var:preset|spacing|60","right":"var:preset|spacing|60"}},"elements":{"link":{"color":{"text":"var:preset|color|base-2"}}}},"textColor":"base-2","fontSize":"x-large"} -->
<p class="has-base-2-color has-text-color has-link-color has-x-large-font-size" style="padding-top:var(--wp--preset--spacing--60);padding-right:var(--wp--preset--spacing--60);padding-bottom:var(--wp--preset--spacing--60);padding-left:var(--wp--preset--spacing--60)">Quote</p>
<!-- /wp:paragraph --></blockquote>
<!-- /wp:quote -->

The editor and frontend should display the background images:

Screenshot 2024-07-08 at 12 54 27 PM

Trac ticket: https://core.trac.wordpress.org/ticket/61588


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions
Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

ramonjd added 3 commits July 8, 2024 11:55
output any background styles, even if there's no background image - this is so users can extend/overwrite theme.json styles
@ramonjd ramonjd force-pushed the add/background-global-styles-panel-for-blocks branch from 210feca to 9b4a6eb Compare July 8, 2024 02:40
@ramonjd ramonjd self-assigned this Jul 8, 2024
@ramonjd ramonjd marked this pull request as ready for review July 8, 2024 02:58
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jul 8, 2024

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props ramonopoly, aaronrobertshaw, noisysocks.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Copy Markdown

@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 putting this together @ramonjd 👍

✅ Theme.json defined background images display in editors and frontend
✅ Code changes match GB PR

Editor Frontend
Screenshot 2024-07-08 at 3 07 02 PM Screenshot 2024-07-08 at 3 07 14 PM

I left a few minor nits as inline comments.

@aaronrobertshaw
Copy link
Copy Markdown

Thanks for adding the @ticket comments, missed those in my review, sorry.

Latest changes LGTM 🚀

@ramonjd
Copy link
Copy Markdown
Member Author

ramonjd commented Jul 8, 2024

I appreciate the quick review!

@noisysocks
Copy link
Copy Markdown
Member

Committed in r58797.

@noisysocks noisysocks closed this Jul 24, 2024
@mukeshpanchal27
Copy link
Copy Markdown
Member

@ramonjd @joemcgill @felixarntz

I ran local Server-Timing benchmarks with and without these PR changes and found that the PR is responsible for ~3% regression.

Server-Timing benchmarks

Mertic Beta 3 Beta 3 without these PR changes Diff % Diff abs.
Response Time 69.05 65.67 -4.90% -3.38
wp-before-template 30.94 29.67 -4.10% -1.27
wp-template 35.45 34.15 -3.67% -1.30
wp-total 66.87 63.97 -4.34% -2.90

@ramonjd
Copy link
Copy Markdown
Member Author

ramonjd commented Oct 15, 2024

I ran local Server-Timing benchmarks with and without these PR changes and found that the PR is responsible for ~3% regression.

Interesting. Thanks for the ping!

I'm at the end of my day, but I wonder if the following needs to be cached:

https://github.com/WordPress/wordpress-develop/pull/6836/files#diff-1be8a8089d87d1b4b6e449c0967680d6f7c170d13f247180a975cbea5e54070fR310

@mukeshpanchal27 Are you comparing against local changes using https://github.com/mukeshpanchal27/compare-wp-performance? Could you share your workflow? Thanks!

@mukeshpanchal27
Copy link
Copy Markdown
Member

@felixarntz
Copy link
Copy Markdown
Member

@ramonjd @mukeshpanchal27

I'm at the end of my day, but I wonder if the following needs to be cached:

https://github.com/WordPress/wordpress-develop/pull/6836/files#diff-1be8a8089d87d1b4b6e449c0967680d6f7c170d13f247180a975cbea5e54070fR310

Good suggestion. Let's first verify that that method is indeed responsible for a notable performance decline. Maybe just comment it out and rerun the benchmarks to compare?

@ramonjd ramonjd deleted the add/background-global-styles-panel-for-blocks branch October 16, 2024 00:40
@ramonjd
Copy link
Copy Markdown
Member Author

ramonjd commented Oct 16, 2024

Let's first verify that that method is indeed responsible for a notable performance decline. Maybe just comment it out and rerun the benchmarks to compare?

Commented over here: WordPress/performance#1572 (comment)

I'm not sure there's much to see here yet.

I also mentioned that I think there needs to be a caching strategy for resolved URIs however:

I think perhaps caching them in WP_Theme_JSON_Resolver as is done with theme_json might work, using get_stylesheet() or get_stylesheet_directory() as a key. I'll add it to my list of things to look into.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants