Skip to content

Bump @wordpress/theme to 1.0.0 and migrate WPDS token names - #14

Merged
donnchawp merged 2 commits into
trunkfrom
update/wpds-token-migration
Jul 28, 2026
Merged

donnchawp merged 2 commits into
trunkfrom
update/wpds-token-migration

Conversation

@donnchawp

@donnchawp donnchawp commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #13

Summary

The repo pinned @wordpress/theme 0.13.0, which defines the old short-form colour token names. Upstream renamed the bg and fg groups to background and foreground in 0.16.0, so every --wpds-color-bg-* and --wpds-color-fg-* reference here stops resolving on 1.0.0 and silently drops to its hardcoded fallback. This bumps the package and migrates the names.

Five tokens are affected, across the top menu and footer partials. None of them changed value in the rename, so the migration on its own is visually inert. What does change is one unrelated token, covered below.

A second commit follows up on that. Both of the checks the first commit relied on, spotting the rename and catching the drifted fallbacks, were done by reading the diff, and both are decidable against the token table the package already ships. So the second commit adds stylelint with two of the package's own rules and drops the hardcoded fallbacks entirely.

Changes

First commit, the migration:

  • package.json and the lockfile: @wordpress/theme 0.13.0 to 1.0.0.
  • sass/emerald/_jpcrm_top_menu.scss: rename the five short-form tokens, and correct six hardcoded fallbacks.
  • sass/emerald/_jpcrm_footer.scss: rename, and collapse the three var(--short, var(--long, #hex)) declarations that CRM: Align admin footer with the unified Jetpack footer #8 added to straddle both versions. They have done their job now.

Second commit, the lint:

  • stylelint.config.mjs, new: plugin-wpds/no-unknown-ds-tokens and plugin-wpds/no-token-fallback-values.
  • package.json and the lockfile: stylelint 16.26.1 and postcss-scss 4.0.9, both dev only, and a lint:css script.
  • Makefile: a lint-css target.
  • Both partials again: all 25 hardcoded fallbacks removed.

The stale fallbacks

Six fallbacks in the top menu partial were already wrong against 0.13.0, not just against 1.0.0:

Token Was Actual value
--wpds-dimension-padding-xl 16px 20px
--wpds-color-fg-content-neutral #1d2327 #1e1e1e
--wpds-color-fg-content-neutral-weak (x2) #6d6d6d #707070
--wpds-color-stroke-surface-neutral-weak #dcdcde #f0f0f0
--wpds-color-stroke-interactive-neutral-strong #6c6c6c #6e6e6e

They were inert, because the tokens resolve. But they are what the UI would land on if the token stylesheet ever stopped being inlined, and the same token appeared elsewhere in the file with the correct #1e1e1e, so it was inconsistent with itself.

The first commit corrected them. The second removes them, along with the other nineteen, for the reason below.

The one visible change

--wpds-color-stroke-surface-neutral-weak went from #e4e4e4 to #f0f0f0 in 0.15.0, when the stroke1 contrast target was raised from 2.6 to 2.9. That token draws two things here, so both lighten:

  • the top menu's bottom border
  • the footer's top border

I resolved every declaration in both partials against each version's token table and diffed the results. Those two borders are the only rendered changes in the whole bump.

Dropping the fallbacks

None of the 25 fallbacks could ever be reached. _jpcrm_top_menu.scss:1 imports design-tokens.css, and both partials compile into the same css/jpcrm-emerald.css, so the whole token table is present at :root in the same file that references it. Every var() resolves and the fallback is dead.

They do not help against another plugin either, which was my first thought. A plugin on a pre-0.16 @wordpress/theme defines the short names, which we no longer reference, so there is no collision. A plugin on 1.x defines the same long names at :root, and last loaded wins, but the token is then defined and var() resolves to its value, so the fallback is bypassed anyway. A custom property can only be overwritten with a value, never un-defined, which routes around the fallback by definition.

What they did do was rot quietly. Six of the 25 had drifted out of sync with no visible symptom, and I only found them by hand. That is the argument for the lint rather than the fallback: an unknown token now fails the build-time check loudly instead of falling back to a stale value at runtime.

Upstream's own rule message says fallbacks "should be injected automatically at build time" via postcss-ds-token-fallbacks. We do not need that while the token table is inlined into the same stylesheet. It would matter if we ever move the design-tokens.css import somewhere less global, which is the same refactor as the issue below.

The lint

Two rules, both shipped by @wordpress/theme itself:

  • no-unknown-ds-tokens rejects --wpds-* names that do not exist in the installed version. This is the rule that would have caught the whole bg and fg rename automatically.
  • no-token-fallback-values keeps hardcoded fallbacks out of var().

The config deliberately does not extend a style guide. The Sass sources predate any linting and a full rule set would bury these two under thousands of pre-existing formatting errors. postcss-scss is not optional, the default CSS parser chokes on // comments and @use.

Run it with make lint-css, or npm run lint:css.

It is not a prerequisite of make build yet, which is where it would actually earn its keep, since a release always runs that target. The Makefile is shared with other plugins and adding the prerequisite would break make build in any of them that has no stylelint config. Making that portable needs more thought than this PR should carry, so it goes in its own PR.

A side effect worth knowing about

WordPress core injects an inline @layer wp-ui-components block for its badge component. It references short-form WPDS names with its own fallbacks. Because our stylesheet publishes the entire token table into a global :root, we were overriding core's badge tokens with our package's values. Six of them differed:

Token Core's fallback What we were forcing
bg-surface-neutral #f8f8f8 #fcfcfc
bg-surface-neutral-weak #f0f0f0 #f4f4f4
fg-content-neutral-weak #6d6d6d #707070
bg-surface-success #c5f7cc #c6f7cd
bg-surface-warning #fde6bd #fde6be
bg-surface-caution #fee994 #fee995

After the bump those short names no longer exist, so core's badges get their intended values back. The differences are 1 to 4 units and no such badges render on CRM pages today, so nothing is visibly different. The direction is right though, and it makes the case for moving the design-tokens.css import somewhere more deliberate. Publishing a global :root block means we theme anything on the page that speaks WPDS, which is not what we want. I'll open a separate issue for that.

Testing

Verified on a live install, on the CRM dashboard and a contact record:

footer border-top       rgb(240,240,240)   #f0f0f0, was #e4e4e4
menu-bar border-bottom  rgb(240,240,240)   #f0f0f0, was #e4e4e4
footer background       rgb(252,252,252)   #fcfcfc, unchanged
logo text               rgb(30,30,30)      #1e1e1e, unchanged
a8c byline fill         rgb(112,112,112)   #707070, unchanged
active tab underline    rgb(110,110,110)   #6e6e6e, unchanged
top menu padding-top    20px               unchanged

The check that matters: --wpds-color-bg-surface-neutral and --wpds-color-fg-content-neutral are now undefined on the page, while their long-form counterparts resolve. That confirms the rename was load-bearing. Without this migration those declarations would have quietly fallen back.

Also:

  • Enumerated every --wpds-* reference in the loaded jpcrm-emerald.css against :root on both pages. Zero undefined.
  • Checked all 25 var(--wpds-*) references in the Sass sources against 1.0.0's design-tokens.css, for both name and fallback value. All match.
  • No short-form names and no nested var() straddles remain in the Sass sources.
  • npm run build compiles clean. The compiled output inlines 188 token definitions, none short-form.
  • Mobile: at 500px the footer keeps margin: 0 from the 782px rule, without triggering the 480px stacking. As intended.

For the second commit:

  • Both rules fire on real input. Before the removal no-token-fallback-values flagged exactly 25 problems, matching the 25 known references. no-unknown-ds-tokens reports nothing on the current source, so I checked it against a throwaway file: it rejects --wpds-color-fg-content-neutral and passes the long-form name. That is the rename it needs to catch.
  • Diffed the compiled stylesheet against a snapshot of the previous build. Every changed line is a fallback removal. The :root table is identical, so nothing renders differently, and the live values above still hold.
  • All four emerald variants, plain, min, rtl and min.rtl: 167 unique token names defined (the 188 declarations above include repeats), 15 referenced, none undefined, no fallbacks left. Worth checking explicitly now that an unknown token renders as an unset property rather than degrading to a hex.
  • make lint-css exits 2 on a bad token and 0 once it is removed.

I didn't attach before and after screenshots. The only rendered difference is #e4e4e4 to #f0f0f0 on two 1px borders, so the pair would look identical. The computed values above are the better evidence.

Note on the lockfile

The lockfile is up 1183 lines against trunk for two version changes, and it is all dev weight.

892 of those come from stylelint and its 63 packages. The rest is @wordpress/theme 1.0.0 pulling in 22 transitive packages (@wordpress/compose, @wordpress/i18n, tannin, mousetrap and friends) as dependencies of the ThemeProvider React component it now ships. Nothing here imports it, only the CSS file, so none of that reaches the bundle. The lock has zero non-dev packages in it at all, and the root has no runtime dependencies.

stylelint.config.mjs is a new top-level file, and ship_paths in scripts/build-plugin.sh is an explicit allow-list, so it stays out of the release zip.

Follow-ups

  • Make lint-css a prerequisite of make build, in a way that survives the Makefile being copied to plugins without a stylelint config.
  • The release workflow pins no Node version. create-release.yml:41 runs a bare npm install with no actions/setup-node and there is no .nvmrc. 1.0.0 requires ^20.19.0 || >=22.13.0 and is ESM only, and stylelint now runs in that same path. Also shared tooling, so it belongs with the item above.
  • Move the design-tokens.css import somewhere less global, per the badge section.

The repo pinned @wordpress/theme 0.13.0, which defines the old short-form
colour token names. Upstream renamed the bg and fg groups to background and
foreground in 0.16.0, so every --wpds-color-bg-* and --wpds-color-fg-*
reference here stops resolving on 1.0.0 and silently drops to its fallback.

Rename all five affected tokens in the top menu and footer partials, and
collapse the three var(--short, var(--long, #hex)) declarations the footer
used to straddle both versions.

While in there, correct six hardcoded fallbacks in the top menu partial that
were already wrong against 0.13.0, not just against 1.0.0: padding-xl fell
back to 16px where the token is 20px, fg-content-neutral to #1d2327 where it
is #1e1e1e (the same token elsewhere in the file already used #1e1e1e),
fg-content-neutral-weak to #6d6d6d where it is #707070, and
stroke-interactive-neutral-strong to #6c6c6c where it is #6e6e6e. They were
inert because the tokens resolve, but they are what the UI would fall back to
if the token stylesheet ever stopped being inlined.

Two borders change appearance. --wpds-color-stroke-surface-neutral-weak went
from #e4e4e4 to #f0f0f0 in 0.15.0, when the stroke1 contrast target was
raised from 2.6 to 2.9. That token draws the top menu's bottom border and the
footer's top border, so both lighten. Resolving every declaration in both
partials against each version's token table confirms those two are the only
rendered changes.
@donnchawp

Copy link
Copy Markdown
Contributor Author

This was generated by AI during triage.

Follow-ups opened:

Neither blocks this PR.

@donnchawp donnchawp added this to the 6.8.3 milestone Jul 28, 2026
The previous commit corrected six hardcoded fallbacks by hand, and found the
rename it migrated by reading the diff. Both of those checks can be made
against the token table @wordpress/theme already ships, so lint them instead.

Add stylelint with two of the package's own rules. no-unknown-ds-tokens
rejects --wpds-* names that do not exist in the installed version, which is
what would have caught the bg and fg rename. no-token-fallback-values keeps
hardcoded fallbacks out of var().

Drop all 25 fallbacks from the two emerald partials. None of them could ever
be reached: _jpcrm_top_menu.scss imports design-tokens.css into the same
compiled stylesheet that references it, so every token resolves from the
:root block in that file. Six had silently drifted out of sync, which is the
argument against keeping them around.

The compiled CSS differs from the previous build only by the removed
fallbacks. The 167-token :root table is unchanged, so nothing renders
differently, and all four emerald variants resolve their 15 references with
none left undefined.

The config does not extend a style guide, deliberately. The Sass sources
predate any linting and a full rule set would bury the two token rules under
thousands of pre-existing formatting errors.

Run it with make lint-css. It is not a prerequisite of make build yet,
because that target is shared with other plugins that have no stylelint
config, and making it portable needs more thought than this PR should carry.
@donnchawp
donnchawp merged commit 8dbe017 into trunk Jul 28, 2026
1 check passed
@donnchawp
donnchawp deleted the update/wpds-token-migration branch July 28, 2026 15:15
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.

Bump @wordpress/theme to 1.x and migrate to renamed WPDS token names

1 participant