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

Fix block style variation custom CSS output on the front end #6797

Conversation

tellthemachines
Copy link
Contributor

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

Syncs the changes from WordPress/gutenberg#62526 to core.


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.

Copy link

github-actions bot commented Jun 13, 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 isabel_brison, aaronrobertshaw.

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

Copy link

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.

@aaronrobertshaw
Copy link

While testing, I ran into an issue where custom CSS for a variation's inner block types isn't working on this branch. It works with Gutenberg trunk active.

Theme.json snippet added two TT4
{
	"styles": {
		"blocks": {
			"variations": {
				"Custom": {
					"blockTypes": [
						"core/group"
					],
					"color": {
						"background": "skyblue"
					},
					"spacing": {
						"padding": {
							"top": "1em",
							"right": "1em",
							"bottom": "1em",
							"left": "1em"
						}
					},
					"blocks": {
						"core/group": {
							"color": {
								"background": "aliceblue"
							},
							"spacing": {
								"padding": {
									"top": "1.5em",
									"right": "0.5em",
									"bottom": "1.5em",
									"left": "0.5em"
								}
							},
							"css": "outline: 3px dashed red;"
						}
					}
				}
			},
			"core/button": {
				"variations": {
					"outline": {
						"spacing": {
							"padding": {
								"bottom": "calc(0.6rem - 1px)",
								"left": "calc(1rem - 1px)",
								"right": "calc(1rem - 1px)",
								"top": "calc(0.6rem - 1px)"
							}
						},
						"border": {
							"width": "1px"
						},
						"css": "outline: 3px dashed ivory;"
					}
				}
			},
}
This Branch With Gutenberg Active
Screenshot 2024-06-16 at 2 47 09 PM Screenshot 2024-06-16 at 2 46 59 PM

Note on this branch alone, the custom css adding the red outline to inner Group blocks with the "Custom" block style variation is not getting applied.

Quickly dumping out some data and styles at different points, I could see the same variations data being given to the theme.json class in both Core and Gutenberg however the resulting CSS stylesheet for core omits the custom css for the variation's inner blocks.

I haven't had much success putting my finger on the cause just yet and need to switch onto some other tasks that need to make WP6.6 beta3. I'll try and help dig deeper tomorrow.

Some unit tests might also help debug and prevent some future regressions. What do you think?

P.S. We should also add a @since 6.6.0 note to get_styles_for_block flagging it as the release custom css for variations was added or "fixed".

@aaronrobertshaw
Copy link

Is it possible that Gutenberg is working due to the changes associated with WordPress/gutenberg#62357?

@tellthemachines
Copy link
Contributor Author

Thanks for spotting that @aaronrobertshaw! I've fixed the issue now. It was due to one of the changes in Gutenberg, but I've managed to safely add part of that code here without affecting output for other custom CSS.

}

// 7. Generate and append any custom CSS rules pertaining to nested block style variations.
if ( isset( $node['css'] ) && ! $is_root_selector ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because in core we're not setting the css property in get_block_nodes, this will only be true for nested block style variations.

Copy link

@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 the quick turnaround on that fix @tellthemachines 🚀

I can confirm the custom css for inner block type styles for variations is now getting applied correctly on the frontend.

Screenshot 2024-06-17 at 12 13 51 PM

I think we might aso need to add to the @since 6.6.0 comment for get_styles_for_block so it covers the changes here.

@tellthemachines
Copy link
Contributor Author

Committed in r58421.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants