Add wp-theme as a style dependency of wp-components#80362
Conversation
|
Flaky tests detected in ba13e60. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/29513155595
|
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
| gutenberg_url( 'build/styles/base-styles/admin-schemes' . $suffix . '.css' ), | ||
| array( 'wp-theme' ), | ||
| array(), | ||
| $version |
There was a problem hiding this comment.
Removing this dependency should be fine, since wp-edit-blocks directly depends on wp-theme, and editor styles depend on wp-components.
But we may still need to tweak the theme package's README, since it claims that wp-theme loads through shared base styles on standard admin pages. We should probably remove / generalize that claim to make it more future-proof
There was a problem hiding this comment.
I'll update the readme separately 👍
|
Just to confirm, do consumers who want to use design tokens without depending on For example, plugin developers might register their own custom settings pages, where they may want to use design tokens to build their UI. I am one of those people who want to use design tokens to add some UI to the dashboard. Are there any concerns about always enqueuing design tokens for all screens? |
I touched on this in my merge proposal post, but the short answer is: Yes, you do need to enqueue it, and yes, we eventually should expect it to be enqueued for all screens. Under "What's next":
|
In WordPress/wordpress-develop#12560, I noticed that:
|
Thank you for explaining it in detail!
This appears to be true. I checked the style handles in a tree format using code like the following: Detailsadd_action( 'admin_print_footer_scripts', function () {
$wp_styles = wp_styles();
$done = $wp_styles->done;
// Recursively expand a handle into a { handle, deps } node.
$build = function ( $handle, $seen ) use ( &$build, $wp_styles, $done ) {
$dep = $wp_styles->registered[ $handle ] ?? null;
// Unregistered handle: leaf.
if ( null === $dep ) {
return array(
'handle' => $handle,
'deps' => array(),
);
}
// Already on this branch: stop to avoid cycles.
if ( isset( $seen[ $handle ] ) ) {
return array(
'handle' => $handle,
'deps' => array(),
);
}
$seen[ $handle ] = true;
$children = array();
foreach ( $dep->deps as $child ) {
$children[] = $build( $child, $seen );
}
return array(
'handle' => $handle,
'deps' => $children,
);
};
// One tree per enqueued handle.
$tree = array();
foreach ( $wp_styles->queue as $handle ) {
$tree[] = $build( $handle, array() );
}
// Does this subtree reach wp-theme?
$contains = function ( $node ) use ( &$contains ) {
if ( 'wp-theme' === $node['handle'] ) {
return true;
}
foreach ( $node['deps'] as $child ) {
if ( $contains( $child ) ) {
return true;
}
}
return false;
};
// Keep only the roots that pull in wp-theme.
$tree = array_values( array_filter( $tree, $contains ) );
// Print the tree to the browser console.
wp_print_inline_script_tag(
sprintf(
'( function () {
var tree = %s;
function label( node ) {
return node.handle;
}
function walk( node ) {
if ( ! node.deps.length ) {
console.log( label( node ) );
return;
}
console.group( label( node ) );
node.deps.forEach( walk );
console.groupEnd();
}
console.group( "Style deps tree (%d root handles)" );
tree.forEach( walk );
console.groupEnd();
} )();',
wp_json_encode( $tree ),
count( $tree )
)
);
} );
Therefore, I found that design tokens are effectively enqueued on all dashboard pages. |
* Add wp-theme as a style dependency of wp-components. * Remove wp-theme bootstrap from wp-base-styles. * Remove redundant wp-theme registration comment. Co-authored-by: mirka <0mirka00@git.wordpress.org> Co-authored-by: ciampo <mciampini@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: aduth <aduth@git.wordpress.org>


What?
Adds
wp-themeas a style dependency ofwp-componentsin the Gutenberg plugin asset registration, and removes thewp-themebootstrap fromwp-base-styles.Why?
@wordpress/componentsstyles consume--wpds-*design tokens defined by thewp-themestylesheet. The JS packages already declare this dependency, but the style graph did not.admin-schemes.css(which is essentially what thewp-base-stylesstylesheet handle loads) does not consume tokens itself, so it is not quite logical thatwp-base-stylesdeclareswp-themeas a dependency. We were only hooking intowp-base-stylesas a kind of convenience. Entry points that need tokens should declare the dependency explicitly.I was rethinking this in the context of WordPress/wordpress-develop#12560, and this PR basically matches the stylesheet dependency logic we're implementing upstream in Core.
How?
wp-themetowp-componentsstyle dependencies inlib/client-assets.php.wp-themefromwp-base-stylesstyle dependencies.Testing Instructions
npm run build(Gutenberg plugin activated).