Theme: forward ThemeProvider cornerRadius preset to :root for root providers#79153
Theme: forward ThemeProvider cornerRadius preset to :root for root providers#79153ciampo wants to merge 4 commits into
Conversation
|
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. |
3108de9 to
93a39d0
Compare
|
Size Change: +36 B (0%) Total Size: 8.58 MB 📦 View Changed
|
93a39d0 to
dc37527
Compare
Restores `data-wpds-root-provider="true"` on the wrapper when `isRoot`, so prebuilt CSS can forward preset-based settings (e.g. `cornerRadius` in #79153) to `:root` via `:root:has([data-wpds-root-provider="true"]…)`. Dynamic color/cursor values keep using the JS sync in `useLayoutEffect` (they can't be expressed in a static stylesheet). Comment updated to explain the deliberate split.
|
Flaky tests detected in dc37527. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/27557643745
|
|
A couple clarifying questions on the difference in implementation between radius & color/cursor:
|
aduth
left a comment
There was a problem hiding this comment.
LGTM 👍
This was a little tricky to test, since all the border radiuses in Storybook fall within a ThemeProvider wrapper and so testing the :root forwarding required a bit of manual manipulation to copy/paste an element from the inspector to outside the ThemeProvider wrapper. Separately-but-maybe-relatedly it might be a good idea to change some of our hard-coded borderRadius in theme examples to use the tokens.
| Before | After |
|---|---|
![]() |
![]() |
| // block (it also defines base tokens on `:root`) to avoid interfering | ||
| // with the color assertions above. | ||
| describe( 'cornerRadius forwarding', () => { | ||
| const BORDER_RADIUS = '--wpds-border-radius-sm'; |
There was a problem hiding this comment.
Nit: I'd only expect SCREAMING_SNAKE_CASE constant variables at the top-level of the module (ref), so either moving this to be with the rest or renaming it to a camelCase naming scheme.
| beforeAll( () => { | ||
| prebuiltStyle = document.createElement( 'style' ); | ||
| prebuiltStyle.textContent = readFileSync( | ||
| join( __dirname, '../prebuilt/css/design-tokens.css' ), |
There was a problem hiding this comment.
Tangent: I wonder if we could save ourselves some future headache adopting something like babel-plugin-transform-import-meta so we could start using (and avoid future migration to) import.meta.dirname since __dirname doesn't exist in true ESM. Ideally we'd upgrade Jest and try to start using some of their native ESM support, but that's a bigger task.
| ### Enhancements | ||
|
|
||
| - `ThemeProvider`: forward the `cornerRadius` preset to the document element when `isRoot` is set, matching `color` and `cursor`. [#79153](https://github.com/WordPress/gutenberg/pull/79153). |
There was a problem hiding this comment.
Arguably a bug fix, but since it hasn't released yet I suppose it's not a bug quite yet!
Restore the `:root:has([data-wpds-root-provider="true"][data-wpds-corner-radius="…"])` selectors for each corner-radius preset mode in the Terrazzo config (and the generated prebuilt CSS) so a root `ThemeProvider` applies the `--wpds-border-radius-*` tokens to the document element, consistent with how `color` and `cursor` tokens already behave. Follow-up to #78816 (comment)
Add coverage for the prebuilt `:root:has( [data-wpds-root-provider='true']… )` rule: a root provider forwards its corner-radius preset to the document element, while a non-root provider does not. Loads the prebuilt design-token CSS (where the border-radius preset values live) to exercise the cascade.
dc37527 to
415e57d
Compare


Follow-up to #78816 (review thread).
What
A root
ThemeProvider(isRoot) now forwards itscornerRadiuspreset to the document element, so--wpds-border-radius-*applies to<html>— not just the provider's scoping<div>. This matches howcolorandcursoralready behave.Why
color/cursorfrom a root provider already cascade to:root;cornerRadiuswas the odd one out. Mixed pages (React UI + PHP-rendered admin HTML) consume the tokens outside the React root, so the radius preset should reach<html>too.Only
isRootproviders are affected — non-root nested providers still scope their preset locally.How
Each
corner-radius-*mode interrazzo.config.tsgains a:root:has([data-wpds-root-provider="true"][data-wpds-corner-radius="…"])selector (plus regenerated CSS + CHANGELOG).Test plan
ThemeProviderand switch the preset; confirm--wpds-border-radius-*updates on:rootin DevTools.:root.color/cursorroot forwarding still works and the default (subtle) preset matches existing appearance.Note on the generated CSS
src/prebuilt/css/design-tokens.cssis regenerated bynpm run build(inpackages/theme); running the full build produces this exact diff with no other changes.Use of AI
Made with Cursor.