Skip to content

Theme: Add DEFAULT_THEME_SETTINGS export - #87915

Open
ciampo wants to merge 7 commits into
trunkfrom
t3/theme-default-values-api
Open

ciampo wants to merge 7 commits into
trunkfrom
t3/theme-default-values-api

Conversation

@ciampo

@ciampo ciampo commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

What?

Follow-up to #87839. See the discussion there.

@wordpress/theme exports DEFAULT_THEME_SETTINGS: the values ThemeProvider uses for each setting that is neither set nor inherited. A nested provider can pass one of them to reset that setting.

Why?

A nested ThemeProvider inherits every setting it omits, so omitting a setting can't bring back its default. To get the default background inside a provider that overrides it, a consumer has to hard-code #fcfcfc. The site editor and boot did that until #87839 moved the value to ADMIN_CONTENT_BACKGROUND in @wordpress/admin-ui, which is still a second copy of a theme default. A plain "white" such as #fff is not a substitute: it flattens the generated neutral surfaces. Only @wordpress/theme knows its defaults, so it should publish them.

How?

  • New frozen export, shaped like the provider settings:
    DEFAULT_THEME_SETTINGS = {
    	color: { primary: '#3858e9', background: '#fcfcfc' },
    	cursor: { control: 'pointer' },
    	cornerRadius: 'subtle',
    };
    Each value can be used on its own: color={ { background: DEFAULT_THEME_SETTINGS.color.background } } resets only the background and keeps the inherited primary. Spreading the object resets everything.
  • The color values come from the seeds that the provider already uses, so they can't drift. The provider's cornerRadius fallback now reads the constant. The provider sets no cursor by default, so cursor.control repeats the value of the --wpds-cursor-control token, and a test compares the two.
  • edit-site and boot use it in place of ADMIN_CONTENT_BACKGROUND. They ship with the same @wordpress/theme, so they don't need a fallback. ADMIN_CONTENT_BACKGROUND stays for scripts that bundle @wordpress/admin-ui and support older WordPress versions.
  • The object is frozen, because wp.theme is a global that every script on the page shares.
  • Documented in the export's JSDoc, the JSDoc of each setting, the README, and the Nesting And Inheriting story, which now resets the background at its deepest level. Scripts that support WordPress versions without the export read it with a fallback:
    const background = DEFAULT_THEME_SETTINGS?.color.background ?? '#fcfcfc';

Note

The JSDoc (@since 7.3.0) and the README say that WordPress 7.3 and Gutenberg 24.7 add the export. If this merges after the Gutenberg 24.7 RC, or misses WordPress 7.3, update both.

Options considered

1. Export the default values (this PR). One constant shaped like the settings.

  • Uses the existing contract: a value is a value. No new resolution rules, and the provider doesn't change.
  • Typed and discoverable in the editor. Works with spreading and partial resets.
  • Also useful outside the provider, for example to paint a body background or to compare against.
  • Same performance as today: the default background still hits the prebuilt-ramp fast path.
  • Older WordPress: wp.theme.DEFAULT_THEME_SETTINGS is undefined. With optional chaining and a fallback value, the consumer gets the right color on every version. With optional chaining alone, the setting inherits, as with a separate prop. This is the only option where the consumer chooses what happens on an older version.

2. A 'default' keyword on each setting (color={ { background: 'default' } }).

  • Reads well, and the provider resolves it, so no import is needed.
  • cursor.control already accepts 'default' as a real value (the CSS default cursor). The keyword is ambiguous there. 'initial', as in CSS, avoids the clash.
  • Not discoverable for colors: 'default' | string collapses to string in TypeScript.
  • Older WordPress: the provider throws on a color it can't parse, so a plugin passing the keyword crashes, and it can't supply a fallback.
  • Each setting needs its own resolution code, and the keyword must not reach the context, or children would inherit the keyword instead of the color.

3. A separate prop (inherit={ false }, reset).

  • Older WordPress ignores the unknown prop, so there is no error. But the setting then inherits from the parent, and the old provider can't use a fallback the consumer supplies. In the site editor's content area under the Modern admin color scheme, that means dark surfaces (#121514) with no error to explain them.
  • All-or-nothing. The real call sites reset the background but keep the admin color scheme's primary. Partial resets would need reset={ [ 'background' ] }, which repeats the settings shape as a second API.
  • Interacts with isRoot and the context in ways that need their own rules.

4. null as an explicit reset (background: null resets, undefined inherits).

  • Typed (string | null). Older WordPress treats null as omitted: no error, but the setting inherits, with the same result as a separate prop.
  • The difference between null and undefined is easy to miss, and background: null reads as "no background".

5. Light and dark presets (LIGHT_THEME, DARK_THEME).

  • The default already is the light theme, so DEFAULT_THEME_SETTINGS covers the light case.
  • The package has no reviewed dark seed, the README states that ThemeProvider has no light or dark mode, and no caller needs one today. A dark preset is a design decision. It can be a separate export later without changing this one.

6. One flat constant per setting (DEFAULT_BACKGROUND_SEED, …).

  • Degrades like option 1 with optional chaining, without needing the ?..
  • The export list grows with each setting, and the names don't match the prop structure.

7. Keep the value in @wordpress/admin-ui only (#87839, now merged).

  • Works on older WordPress, because admin-ui is bundled.
  • Treats a theme default as an admin concern; non-admin consumers still hard-code it. It works best as a stopgap next to this export, deprecated once the supported WordPress versions include it.

Testing Instructions

  1. Open the site editor (/wp-admin/site-editor.php) with a non-default admin color scheme, for example Midnight.
  2. The content area, modals, and menus look the same as on trunk.
  3. With Extensible site editor enabled in Gutenberg > Experiments, open /wp-admin/admin.php?page=site-editor-v2. The content area looks the same as on trunk.
  4. In the browser console, wp.theme.DEFAULT_THEME_SETTINGS returns the frozen object.
  5. In Storybook, open Design System > Theme > Theme Provider > Nesting And Inheriting. The deepest level is light, with the inherited hot pink accent.

Testing Instructions for Keyboard

No UI changes.

Screenshots or screencast

No visual change in the editor.

Use of AI Tools

Claude Code (Claude Opus 5.5 and Claude Fable 5.2) wrote the code, ran the checks, and drafted this description. A human directed the change and reviews the result.

🤖 Generated with Claude Code

@github-actions github-actions Bot added [Package] Edit Site /packages/edit-site [Package] Theme /packages/theme [Package] Boot /packages/boot labels Dec 3, 2026
@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground Preview in Storybook

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: aduth <aduth@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

📦 Bundle size

Size Change: +66 B (0%)

Total Size: 8.86 MB

📦 View Changed
Filename Size Change
build/modules/boot/index.min.js 55 kB +30 B (+0.05%)
build/scripts/edit-site/index.min.js 377 kB +10 B (0%)
build/scripts/theme/index.min.js 29.2 kB +26 B (+0.09%)

bf4ce79 Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric fa627b7 trunk % Change
timeToFirstByte 46 ms +5% -6.09% 45.55 ms +13.06% -5.49% 0.99%
largestContentfulPaint 72 ms +2.78% -5.56% 76 ms +2.63% -10.53% -5.26%
lcpMinusTtfb 25.45 ms +9.04% -3.34% 24.9 ms +17.47% -10.64% 2.21%
wpBeforeTemplate 23.72 ms +8.6% -3.67% 23.64 ms +20.52% -3.68% 0.34%
wpTemplate 17.73 ms +5.08% -5.36% 18.19 ms +4.07% -6.32% -2.53%
wpTotal 42.56 ms +5.4% -6.48% 42.03 ms +13.94% -5.52% 1.26%
wpMemoryUsage 7.76 MB +0% -0% 7.72 MB +0% -0% 0.45%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric fa627b7 trunk % Change
timeToFirstByte 38.3 ms +4.05% -2.35% 37.05 ms +10.66% -2.83% 3.37%
largestContentfulPaint 68 ms +0% -2.94% 64 ms +6.25% -0% 6.25%
lcpMinusTtfb 29.4 ms +3.4% -4.93% 28 ms +1.96% -3.21% 5%
wpBeforeTemplate 21.01 ms +8.23% -4.05% 20.42 ms +15.82% -1.57% 2.89%
wpTemplate 13.79 ms +5.58% -3.77% 13.36 ms +6.66% -2.77% 3.22%
wpTotal 35.49 ms +3.75% -3.21% 34.33 ms +11.13% -3.52% 3.38%
wpMemoryUsage 6.47 MB +0% -0% 6.43 MB +0% -0% 0.55%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric fa627b7 trunk % Change
mediaProcessingJpeg 326.15 ms +0.84% -0.82% 325.58 ms +1.31% -0.33% 0.18%
mediaProcessingAvif 4852.88 ms +0.13% -0.27% 4862.01 ms +0.96% -0.11% -0.19%
mediaProcessingJpegToAvif 3393.17 ms +0.31% -0.26% 3403.75 ms +0.15% -0.15% -0.31%

media-upload

Metric fa627b7 trunk % Change
jpegUploadProcessing 1462.85 ms +1.49% -0.52% 1449.6 ms +0.32% -0.3% 0.91%
pngUploadProcessing 240.23 ms +1.54% -1.57% 234.71 ms +3.64% -5.17% 2.35%
largeJpegUploadProcessing 1443.41 ms +0.67% -0.62% 1434.1 ms +0.39% -0.32% 0.65%
multipleImageUploadProcessing 1498.58 ms +11.91% -0.81% 1489.2 ms +1.83% -0.28% 0.63%

post-editor

Metric fa627b7 trunk % Change
serverResponse 466.79 ms +7.69% -4.81% 478.88 ms +0.8% -8.63% -2.52%
firstPaint 451.63 ms +7.26% -15.36% 382.06 ms +13.27% -2.96% 18.21%
domContentLoaded 839.1 ms +1.71% -1.3% 819.27 ms +1.62% -2.06% 2.42%
loaded 840.54 ms +1.7% -1.27% 820.69 ms +1.6% -2.06% 2.42%
firstContentfulPaint 474.37 ms +2.12% -4.86% 455.27 ms +2.2% -4.65% 4.2%
firstBlock 2268.59 ms +11.98% -1.52% 2221.36 ms +1.27% -0.67% 2.13%
type 16.91 ms +2.48% -7.45% 16.63 ms +4.69% -4.87% 1.68%
typeWithoutInspector 16.79 ms +4.53% -7.09% 16.38 ms +12.39% -8.49% 2.5%
typeWithTopToolbar 22.2 ms +5.54% -7.25% 22.86 ms +2.14% -5.16% -2.89%
typeContainer 8.98 ms +41.76% -16.37% 8.08 ms +8.54% -7.67% 11.14%
focus 103.93 ms +16.68% -7.21% 108.48 ms +2.93% -6.78% -4.19%
firstFocus 240.26 ms +0% -0% 268.97 ms +0% -0% -10.67%
selectAll 383.21 ms +12.32% -1.41% 398.38 ms +2.2% -3.35% -3.81%
undo 28.8 ms +3.92% -2.19% 29.37 ms +5.62% -4.94% -1.94%
listViewOpen 41.01 ms +5.29% -8.75% 40.39 ms +8.39% -6.98% 1.54%
inserterOpen 39.86 ms +26.17% -3.54% 41.12 ms +7.59% -2.75% -3.06%
inserterHover 10.73 ms +6.71% -10.81% 11.11 ms +11.34% -10.17% -3.42%
inserterSearch 8.32 ms +2.76% -7.21% 7.66 ms +5.61% -6.66% 8.62%
loadPatterns 644.51 ms +3.48% -5.32% 656.33 ms +4.47% -3.14% -1.8%
wpTotal 457.1 ms +7.57% -4.95% 469.33 ms +0.74% -8.8% -2.61%
wpMemoryUsage 14.86 MB +0% -0% 14.82 MB +0% -0% 0.25%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric fa627b7 trunk % Change
serverResponse 480.77 ms +3.52% -8.46% 474.25 ms +2.52% -6.76% 1.37%
firstPaint 449.53 ms +6.4% -17.25% 407.85 ms +15.48% -7.87% 10.22%
domContentLoaded 855.06 ms +5.05% -0.65% 850.08 ms +1.67% -1.13% 0.59%
loaded 856.62 ms +5% -0.66% 851.24 ms +1.67% -1.09% 0.63%
firstContentfulPaint 478.27 ms +7.03% -2.46% 468.73 ms +1.78% -2.17% 2.04%
firstBlock 2677.85 ms +0.4% -0.57% 2626.26 ms +1.65% -0.16% 1.96%
type 17.48 ms +5.32% -6.86% 16.61 ms +7.41% -4.7% 5.24%
navigate 111.06 ms +3.74% -2.11% 123.55 ms +12.29% -10.48% -10.11%
loadPatterns 1553.14 ms +12.3% -9.84% 1564.9 ms +9.74% -13.67% -0.75%
loadPages 973.47 ms +2.8% -3.21% 982.48 ms +1.89% -3.13% -0.92%
wpTotal 471.23 ms +3.63% -8.6% 464.88 ms +2.16% -6.9% 1.37%
wpMemoryUsage 12.84 MB +0% -0% 12.80 MB +0% -0% 0.28%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

bf4ce79 Run

🏁 Flaky tests

Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

As a user I want to be able to create a navigation overlay for a specific navigation block in /test/e2e/specs/site-editor/navigation-overlay-template-part.spec.js, passed after 1 failed attempt.
TimeoutError: locator.click: Timeout 10000ms exceeded.
Call log:
  - waiting for getByRole('region', { name: /(Editor publish|Save panel)/ }).getByRole('button', { name: 'Save', exact: true })

    at Editor.saveSiteEditorEntities (/home/runner/work/gutenberg/gutenberg/packages/e2e-test-utils-playwright/src/editor/site-editor.ts:48:5)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/navigation-overlay-template-part.spec.js:91:4
Navigates the items list via UP/DOWN arrow keys in /test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeFocused() failed

Locator:  getByLabel('Page Two')
Expected: focused
Received: inactive
Timeout:  5000ms

Call log:
  - Expect "toBeFocused" getByLabel('Page Two') with timeout 5000ms
  - waiting for getByLabel('Page Two')
    14 × locator resolved to <button type="button" tabindex="-1" aria-pressed="false" id="view-list-0-198-item-wrapper" class="dataviews-view-list__item" aria-labelledby="view-list-0-198-label" aria-describedby="view-list-0-198-description"></button>
       - unexpected value "inactive"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js:146:49
can use focal point picker to set the focal point of the cover image in /test/e2e/specs/editor/blocks/cover.spec.js, passed after 1 failed attempt.
Error: expect(locator).toHaveValue(expected) failed

Locator:  getByRole('group', { name: 'Focal point' }).getByRole('spinbutton', { name: 'Focal point left position' })
Expected: "20"
Received: "50"
Timeout:  5000ms

Call log:
  - Expect "toHaveValue" getByRole('group', { name: 'Focal point' }).getByRole('spinbutton', { name: 'Focal point left position' }) with timeout 5000ms
  - waiting for getByRole('group', { name: 'Focal point' }).getByRole('spinbutton', { name: 'Focal point left position' })
    14 × locator resolved to <input min="0" step="1" max="100" value="50" type="number" autocomplete="off" inputmode="numeric" id="inspector-input-control-0" aria-label="Focal point left position" class="components-input-control__input _072edfb6454aea97__input"/>
       - unexpected value "50"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/cover.spec.js:434:34
should undo without broken temporary state in /test/e2e/specs/editor/blocks/image.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

- Expected  - 2
+ Received  + 2

- <!-- wp:image -->
- <figure class="wp-block-image"><img alt=""/></figure>
+ <!-- wp:image {"id":24,"sizeSlug":"full","linkDestination":"none"} -->
+ <figure class="wp-block-image size-full"><img src="http://localhost:8891/wp-content/uploads/2026/12/1f28b31e-c07d-4858-9d7b-98aef3a54f2f.png" alt="" class="wp-image-24"/></figure>
  <!-- /wp:image -->
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/image.spec.js:432:49

bf4ce79 Run

@ciampo ciampo self-assigned this Dec 3, 2026
@ciampo ciampo added the [Type] Enhancement A suggestion for improvement. label Dec 3, 2026
@ciampo
ciampo marked this pull request as ready for review December 3, 2026 16:40
@ciampo
ciampo requested a review from a team as a code owner December 3, 2026 16:41
@github-actions
github-actions Bot requested a review from aduth December 3, 2026 16:41

@aduth aduth left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 This does feel like the sort of thing that we should have always included, evidenced by the fact that we've been duplicating hard-coded copies of the defaults in other packages. The backwards-compatibility concerns are ... well, concerning. But the risk may be low and we can document the cautions.

Comment on lines +4 to +37
/**
* The value that `ThemeProvider` uses for each setting when neither the
* provider nor a parent provider sets it. Together they make a light theme.
*
* A nested provider inherits every setting that it omits. To reset a setting
* to its default inside a provider that overrides it, pass the default value:
*
* ```jsx
* <ThemeProvider color={ { background: '#1e1e1e' } }>
* <ThemeProvider
* color={ { background: DEFAULT_THEME_SETTINGS.color.background } }
* >
* { children }
* </ThemeProvider>
* </ThemeProvider>
* ```
*
* WordPress 7.3 and Gutenberg 24.7 add this export to the WordPress copy of
* this package (`wp.theme`). A script that uses `wp.theme` and supports older
* versions gets `undefined` there. Read it with optional chaining, and add a
* fallback value:
*
* ```js
* const background =
* DEFAULT_THEME_SETTINGS?.color.background ?? '#fcfcfc';
* ```
*
* Without the fallback, the setting is `undefined` and the provider inherits
* it from its parent.
*
* The object is frozen, because every script on the page shares it.
*
* @since 7.3.0 Introduced in WordPress core.
*/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is quite long. Though I think it points to a very valid backwards-compatibility concern. I'm not sure how likely it is to be encountered, particularly since we'd usually expect people to be going through packages like @wordpress/boot to get these "defaults" for a page context for example. Maybe that could be risky for our own code if we e.g. use it in @wordpress/admin-ui, which then bundles code that only works in WordPress 7.3+.

I'm not really sure if I have a great suggestion here, though a few ideas come to mind, none of which are really great on their own:

  • Update the typings of DEFAULT_THEME_SETTINGS so that it's possibly-undefined as a hint to consumers. This pushes them to handle the undefined case with optional chaining, but doesn't really enforce anything about a fallback, and is unnecessary in environments where the constant is available.
  • Export the constant on a module subpath like @wordpress/theme/defaults or something. This would only work if those subpaths are bundled and not externalized, and this doesn't seem to be how it works today (maybe it should). It also reintroduces the possibility of drift between THEME_PROVIDER's defaults at wp.theme global (which might be an older copy) vs. the latest version of the package.
  • I was initially keen on the idea of using null as a stated intent of "use the default" (vs. undefined as "inherit"), even before seeing that you listed this as an alternative option you considered. I think there's some minor drawbacks of this and it's not quite so easy to understand, but it saves us from some of these issues.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed on the length. I cut the JSDoc down and left the full fallback guidance in the README. Both now say that bundled packages such as @wordpress/admin-ui need the fallback too, which is the risk you describe for our own code. #87839 has merged since, and it keeps a plain ADMIN_CONTENT_BACKGROUND in admin-ui, so no bundled package has to read this export yet.

I'd keep the current shape of the API, though. My thinking on the three ideas:

  • Possibly-undefined type. edit-site, boot, and anyone who bundles the package would have to write ?. for a value they always have. It also can't require a fallback, as you say.
  • Subpath export. Dependency extraction maps @wordpress/theme/defaults to wp['theme/defaults'] today. Bundling it needs a BUNDLED_PACKAGES change, and that only reaches plugins on a newer @wordpress/scripts. The bundled copy could also differ from the provider in wp.theme, which is the drift you mention.
  • null. An older provider treats null as omitted, so the setting inherits with no error and the consumer can't supply a fallback. With the constant, unguarded code throws right away and guarded code gets the right color. We can still add null later, next to the constant, if we want it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aduth let me know if you're ok with this PR shipping as-is

ciampo and others added 7 commits December 3, 2026 23:39
A nested `ThemeProvider` inherits every setting it omits, so consumers that
need the default background inside a provider that overrides it hard-code
`#fcfcfc`. Export the provider's defaults so they can pass them instead, and
use them in the site editor and boot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ciampo
ciampo force-pushed the t3/theme-default-values-api branch from 41fc55f to bf4ce79 Compare December 3, 2026 22:42

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Boot /packages/boot [Package] Edit Site /packages/edit-site [Package] Theme /packages/theme [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants