Jetpack: resolve WPDS design tokens in legacy dashboard CSS#48750
Jetpack: resolve WPDS design tokens in legacy dashboard CSS#48750CGastrell wants to merge 1 commit into
Conversation
The legacy _inc/ Jetpack settings dashboard's postcss pipeline runs
postcss-custom-properties with preserve: false, which inlines var(--foo)
at build time and strips :root { --foo: value } declarations from the
output. The pipeline only sees the calypso-color-schemes token source, so
any var(--wpds-*) in dashboard SCSS would fall back to whatever hex the
consumer hand-wrote in the var(...) second argument.
Extend the @csstools/postcss-global-data files list to include
@wordpress/theme/design-tokens.css. With both sources loaded, postcss
resolves var(--wpds-*) calls to the real WPDS token values at build time,
matching the long-standing precedent for @automattic/calypso-color-schemes.
This unblocks consumers (e.g. PR #48711) from using raw var(--wpds-*) in
legacy dashboard SCSS without having to manually mirror every token value
into a hex fallback. Hex fallbacks remain valid as defensive coding for
surfaces that may not have run through this postcss pipeline.
Add @wordpress/theme as a direct dependency so the require.resolve call
works deterministically regardless of pnpm hoisting changes (it was
previously only transitive via @wordpress/ui).
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryThis PR did not change code coverage! That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷 |
Related to #48160. Unblocks #48711.
Proposed changes
_inc/Jetpack settings dashboard's postcss pipeline (projects/plugins/jetpack/tools/postcss.config.js) so the@csstools/postcss-global-datafileslist also loads@wordpress/theme/design-tokens.cssalongside the existing@automattic/calypso-color-schemes/root-only/index.css.@wordpress/themeas a direct dependency ofplugins/jetpacksorequire.resolve('@wordpress/theme/design-tokens.css')works deterministically regardless of pnpm hoisting changes (previously it was only available transitively via@wordpress/ui).Why this matters / why postcss-global-data and not a JS import
The legacy
_inc/dashboard's postcss pipeline runspostcss-custom-propertieswithpreserve: false. That plugin inlinesvar(--foo)calls at build time using a fixed list of "global data" sources — and strips any matching:root { --foo: value }declarations from the output. So importing@wordpress/theme/design-tokens.cssfrom JS (the obvious "just load it at runtime" approach) doesn't work: the runtime:root { --wpds-*: ... }block gets stripped during postcss processing, andvar(--wpds-*)calls in consumer SCSS fall back to whatever hex the author hand-wrote in the second argument tovar(...).By adding
@wordpress/theme/design-tokens.csstopostcss-global-data'sfiles, the postcss pipeline gains the WPDS token values at build time.var(--wpds-color-fg-content-success-weak)now resolves to the actual WPDS hex (#008030), matching the long-standing precedent for@automattic/calypso-color-schemes.This unblocks consumers like PR #48711 — they can use raw
var(--wpds-*)in legacy dashboard SCSS without manually mirroring every token value into a hex fallback. The hex fallbacks added by #48711 remain valid as defensive coding for surfaces that haven't run through this postcss pipeline (or for builds where the dependency hasn't resolved yet).Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
This change is build/config-only; verification is via postcss output.
pnpm install(so the new@wordpress/themedep resolves).pnpm jetpack build plugins/jetpack— should run cleanly through thebuild-clientstep (any pre-existing_social-logos.scssSCSS failure is unrelated to this PR).Verify resolution against synthetic input:
Expected output:
.x { color: #008030; background: #cc1818; }— note thatbackgrounddiffers from the inline fallback (#d63638vs#cc1818), proving the WPDS token value is being used, not the SCSS-author-provided fallback.Real-world spot check in
_inc/build/jetpack-ai-admin.css: line that usesvar(--wpds-color-fg-content-neutral-weak, #50575e)(from_inc/client/ai/mcp/style.scss) now resolves to#707070(the WPDS token value) instead of the inline fallback#50575e.After Componentry: migrate Status to @wordpress/ui Text in plugin consumers #48711 lands,
_inc/build/admin.csswill inline the success/error/warning/info indicator colors in the Status / pro-status rule blocks. No surface-level visual change is expected (the fallbacks added by Componentry: migrate Status to @wordpress/ui Text in plugin consumers #48711 already produce the same hex), but the var-based source becomes load-bearing.