Skip to content

Twenty Twenty-One: Serve minified stylesheets - #16416

Open
HrithikDalal wants to merge 1 commit into
WordPress:trunkfrom
HrithikDalal:fix/64109-twentytwentyone-minify-styles
Open

HrithikDalal wants to merge 1 commit into
WordPress:trunkfrom
HrithikDalal:fix/64109-twentytwentyone-minify-styles

Conversation

@HrithikDalal

Copy link
Copy Markdown

Twenty Twenty-One now loads minified stylesheets unless SCRIPT_DEBUG is enabled, the same way Twenty Twenty-Two and Twenty Twenty-Five do (#63012). This picks up #10860 and addresses the review feedback left there:

  • All five frontend stylesheets get a minified copy: style, style-rtl, print, style-dark-mode and style-dark-mode-rtl.
  • The RTL stylesheet uses the suffix data, so right-to-left sites load style-rtl.min.css.
  • The minified files are not committed. They're in .gitignore, built by the cssmin:themes Grunt task for core builds, and by the theme's npm run build for the theme ZIP (added to the minification steps in test-and-zip-default-themes.yml).
  • No child theme check is needed: the theme loads its stylesheets with get_template_directory_uri().
  • The IE files are left in place.
  • style.css gets the same "only served when SCRIPT_DEBUG is enabled" note as Twenty Twenty-Five, with the wording suggested on Minify stylesheets for twentytwentyone theme. #10860.

*.min.css is added to .stylelintignore, so build:stylelint doesn't rewrite the minified files on the next build. The theme's postcss.config.js (postcss-css-variables with preserve: false) is not applied to the minified files, because postcss-cli skips the config file when --use is passed.

Adding cssnano updates a few existing packages in the lockfile within their current ranges. npm run build still reproduces the committed CSS exactly.

The other classic themes will follow in a separate PR, which then unblocks #58519.

Testing

  1. Run npm run build:dev (or npx grunt cssmin:themes --dev) and check that the five .min.css files are created in twentytwentyone/ and twentytwentyone/assets/css/, and that git status doesn't list them.
  2. Activate Twenty Twenty-One and turn on "Dark mode support" in the Customizer.
  3. With SCRIPT_DEBUG set to false, view a post. style.min.css, print.min.css and style-dark-mode.min.css load.
  4. Switch the site to a right-to-left language. style-rtl.min.css and style-dark-mode-rtl.min.css load.
  5. With SCRIPT_DEBUG set to true, the unminified files load as before.
  6. In src/wp-content/themes/twentytwentyone, run npm ci && npm run build twice. The minified files are created and git diff stays empty.

I compared computed styles for every element on a single post with SCRIPT_DEBUG on and off, and they were identical.

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

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Co-authoring the change. Reviewed and tested by me.


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.

Load minified copies of the main, RTL, print and dark mode stylesheets unless `SCRIPT_DEBUG` is enabled, as Twenty Twenty-Two and Twenty Twenty-Five already do.

The minified files are built by the `cssmin:themes` Grunt task for core builds, and by the theme's own `npm run build` for the theme ZIP. They are not committed. The RTL stylesheet uses the `suffix` data so that `style-rtl.min.css` is loaded.

See #64109.
Copilot AI balanced review requested due to automatic review settings December 3, 2026 04:29
@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

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

Props hrithikd.

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


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the stylesheet minification and build-packaging changes.

No open issues 🎉

1 file not reviewed
  • src/wp-content/themes/twentytwentyone/package-lock.json: Generated file
What changed in this PR

Updates Twenty Twenty-One to serve minified frontend stylesheets unless SCRIPT_DEBUG is enabled, aligning it with newer bundled themes.

Changes:

  • Adds minified stylesheet loading, including RTL, print, and dark-mode variants.
  • Generates all five minified files through core builds and theme ZIP packaging.
  • Excludes generated files from Git and Stylelint, and documents the build process.
File Description
src/​wp-content/​themes/​twentytwentyone/​style.css.map Updates mappings for the added header comment.
src/​wp-content/​themes/​twentytwentyone/​style.css Documents debug-only loading and rebuilding.
src/​wp-content/​themes/​twentytwentyone/​style-rtl.css Adds the same documentation to RTL CSS.
src/​wp-content/​themes/​twentytwentyone/​package.json Adds cssnano and five minification scripts.
src/​wp-content/​themes/​twentytwentyone/​package-lock.json Locks minification dependencies and related updates.
src/​wp-content/​themes/​twentytwentyone/​functions.php Selects minified main and print styles, with RTL suffix handling.
src/​wp-content/​themes/​twentytwentyone/​classes/​class-twenty-twenty-one-dark-mode.php Selects minified dark-mode styles for both directions.
src/​wp-content/​themes/​twentytwentyone/​assets/​sass/​01-settings/​file-header.scss Adds build guidance to the source header.
src/​wp-content/​themes/​twentytwentyone/​.stylelintignore Excludes minified CSS from linting.
Gruntfile.js Includes five stylesheets in core minification.
.gitignore Ignores generated minified theme stylesheets.
.github/​workflows/​test-and-zip-default-themes.yml Builds theme assets before ZIP packaging.

Review effort: Balanced

@github-actions

github-actions Bot commented Dec 3, 2026

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

  • 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.

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