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 library and global styles stylesheet ordering when a block … #7088

Closed
wants to merge 2 commits into from

Conversation

talldan
Copy link
Contributor

@talldan talldan commented Jul 25, 2024

Trac ticket: https://core.trac.wordpress.org/ticket/61748
Gutenberg issue: WordPress/gutenberg#63912
Gutenberg PR: WordPress/gutenberg#63918

What?

Reorders the dependencies for block-style-variations-styles

Why?

The order of the dependencies here was causing different ordering of stylesheets on the page

When a theme is using theme.json presets that match the naming used by core, this can suddenly cause those core styles to override those from the theme.json (the css variables from core take precedence over those generated from the theme.json.

Props to @aaronrobertshaw for spotting the problematic line of code

Testing Instructions

  • Alter the Twenty Twenty Four theme.json file to include a font size with the slug normal that is something fairly large, like 2rem
  • Make a page with some text using that font size and preview it - note that the text is correctly sized to 2rem
  • Add a button with the Outline style on the same page and preview it again

Expected: the text is still 2rem
Before: the text was incorrectly 16px

Screenshots or screencast

Before

Regular button Outline button
Screenshot 2024-07-25 at 10 33 43 AM Screenshot 2024-07-25 at 10 33 32 AM

After

Regular button Outline button
Screenshot 2024-07-25 at 10 33 57 AM Screenshot 2024-07-25 at 10 34 08 AM

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.

@talldan talldan added the bug label Jul 25, 2024
@talldan talldan self-assigned this Jul 25, 2024
Copy link

github-actions bot commented Jul 25, 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 talldanwp, aaronrobertshaw, andrewserong, mukesh27.

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

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.

I've given this another run using this PR's specific branch. LGTM

✅ Could replicate issue
✅ Applying the fix resolves the problem
✅ Fix works regardless of whether core block assets are loaded separately
✅ Code changes match WordPress/gutenberg#63918

I used the following font size definition within my theme.json under settings.typography.fontSizes:

				{
					"fluid": false,
					"name": "Normal",
					"size": "4.05rem",
					"slug": "normal"
				},

To toggle separate loading of core assets in TT4 I added the following to the functions.php file:

add_filter( 'should_load_separate_core_block_assets', '__return_false', 11 );

Separate Assets

Before After
Screenshot 2024-07-25 at 1 14 37 PM Screenshot 2024-07-25 at 1 15 43 PM

Consolidated Assets

Before After
Screenshot 2024-07-25 at 1 08 20 PM Screenshot 2024-07-25 at 1 07 51 PM

Visual Results

Before After
Screenshot 2024-07-25 at 1 02 53 PM Screenshot 2024-07-25 at 1 04 05 PM

Copy link
Contributor

@andrewserong andrewserong left a comment

Choose a reason for hiding this comment

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

I followed similar steps to Aaron's testing above, and this is working nicely for me, too!

image

The style registration order now matches what happens normally when a block style variation isn't involved. LGTM!

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.

@mukeshpanchal27
Copy link
Member

Mark ready for commit.

@talldan
Copy link
Contributor Author

talldan commented Aug 5, 2024

committed to trunk in r58850

@talldan talldan closed this Aug 5, 2024
@talldan talldan deleted the fix/stylesheet-ordering branch August 5, 2024 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants