Register wp-theme design tokens stylesheet#12564
Conversation
The `wp-theme` JS package is registered in Core, but its accompanying design tokens stylesheet was only registered in the Gutenberg plugin. Without it, token-consuming styles could see undefined values. Register a `theme` package style in `wp_default_styles()` pointing to `/wp-includes/css/dist/theme/design-tokens.css`, add it as a dependency of `wp-components`, and load it first among the editor styles so token values resolve before consuming rules. Mirrors the Gutenberg setup. Add unit tests covering registration, the `wp-components` dependency, and the editor style ordering. Fixes #65646.
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Trac ticket
Fixes https://core.trac.wordpress.org/ticket/65646
Summary
The
wp-themeJS package is registered in Core, but its accompanying design tokens stylesheet was only registered in the Gutenberg plugin. Without the stylesheet, token-consuming styles may see undefined values. Although first-party usage injects fallback values at build time, the intended behaviour is that the design tokens stylesheet is actually loaded wherever design tokens are used.Changes
In
wp_default_styles():themepackage style pointing to/wp-includes/css/dist/theme/design-tokens$suffix.css(special-cased likebase-styles, since the filename is not the defaultstyle.css).wp-themeas a dependency ofwp-componentsso token values are defined before the consuming styles reference them.wp-themefirst among the editor (wp-edit-blocks) dependencies, and add it to the RTL styles list for consistency with the other package styles.This mirrors the Gutenberg plugin setup.
Unit tests were added to
tests/phpunit/tests/dependencies/styles.phpcovering registration of the handle/src, thewp-componentsdependency, and the editor style ordering.Note for reviewers
The registered file
css/dist/theme/design-tokens.cssis synced from the Gutenberg build (like all othercss/dist/*assets), so a Gutenberg version bump that outputs thetheme/styles directory must precede or accompany this change. Until then the handle resolves to a file that is not yet present in Core.Testing instructions
phpunit tests/phpunit/tests/dependencies/styles.php.wp-themehandle is registered and thatwp-componentsandwp-edit-blocksdepend on it.