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

Update custom CSS handling to be consistent with block global styles. #6750

Conversation

tellthemachines
Copy link
Contributor

@tellthemachines tellthemachines commented Jun 7, 2024

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

Syncs changes from WordPress/gutenberg#62357.

Steps for testing:

  1. Test with custom CSS added at base level and at block level, in theme.json or through the global styles UI.
  2. With TT4 enabled, check that custom CSS for blocks is loaded in the front end only when the block is present on the page;
  3. Add add_filter( 'should_load_separate_core_block_assets', '__return_false', 11 ); to the theme's functions.php and check that custom CSS for all blocks always loads in the front end.

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 7, 2024

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.

@tellthemachines tellthemachines marked this pull request as ready for review July 9, 2024 06:12
Copy link

github-actions bot commented Jul 9, 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, andrewserong.

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.

Thanks for putting this together @tellthemachines 👍

✅ Code changes align with Gutenberg PR
✅ With separate block assets loading, custom css is only loaded when block is present
✅ Without separate block assets loading, custom css is always loaded
✅ Same results when testing custom css via global styles or theme.json

LGTM ✨

@tellthemachines tellthemachines self-assigned this Jul 10, 2024
@tellthemachines tellthemachines added the props-bot Adding this label triggers the Props Bot workflow for a PR. label Jul 10, 2024
@github-actions github-actions bot removed the props-bot Adding this label triggers the Props Bot workflow for a PR. label Jul 10, 2024
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.

Code-wise this is looking good to me, too. The one difference I noticed while testing is that with a classic theme active, it appears that the customizer's Additional CSS doesn't update in real-time with this PR applied.

Can anyone reproduce this issue, or is it just my environment?

Trunk

2024-07-10.11.34.59.mp4

This PR

2024-07-10.11.37.02.mp4

This feature is otherwise testing well for me in block themes, the site editor and post editor, and with the styles being output correctly on the site frontend.

@tellthemachines
Copy link
Contributor Author

Thanks for reviewing, folks!

Can anyone reproduce this issue, or is it just my environment?

I could reproduce that locally; it was due to a missing check that made sure dequeuing customizer CSS only happened for block themes. I've replaced the check now so things should work exactly as they do in trunk.

@tellthemachines
Copy link
Contributor Author

I've just put up a PR to fix this in Gutenberg too: WordPress/gutenberg#63331

@aaronrobertshaw
Copy link

Thanks for the quick fix 🚀

I could replicate the issue and can confirm the latest tweak in 56d5448 fixes it.

Before After
Screen.Recording.2024-07-10.at.2.50.24.PM.mp4
Screen.Recording.2024-07-10.at.2.48.52.PM.mp4

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.

That's testing nicely for me in classic themes now, while block themes and custom CSS continue to work as expected. Thanks for the follow-up!

@tellthemachines
Copy link
Contributor Author

Thanks for re-testing! Committed in r58703,

@noisysocks
Copy link
Member

Thanks for committing this early in the 6.7 cycle ❤️

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.

4 participants