Repository navigation
Conversation
🤖 PR meta 🤖🎉 PropsIf 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. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the 📦 Bundle sizeSize Change: +66 B (0%) Total Size: 8.86 MB 📦 View Changed
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
🏁 Flaky testsSome 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
|
aduth
left a comment
There was a problem hiding this comment.
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.
| /** | ||
| * 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. | ||
| */ |
There was a problem hiding this comment.
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_SETTINGSso that it's possibly-undefined as a hint to consumers. This pushes them to handle theundefinedcase 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/defaultsor 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 atwp.themeglobal (which might be an older copy) vs. the latest version of the package. - I was initially keen on the idea of using
nullas a stated intent of "use the default" (vs.undefinedas "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.
There was a problem hiding this comment.
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/defaultstowp['theme/defaults']today. Bundling it needs aBUNDLED_PACKAGESchange, and that only reaches plugins on a newer@wordpress/scripts. The bundled copy could also differ from the provider inwp.theme, which is the drift you mention. null. An older provider treatsnullas 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 addnulllater, next to the constant, if we want it.
There was a problem hiding this comment.
@aduth let me know if you're ok with this PR shipping as-is
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>
41fc55f to
bf4ce79
Compare
What?
Follow-up to #87839. See the discussion there.
@wordpress/themeexportsDEFAULT_THEME_SETTINGS: the valuesThemeProvideruses for each setting that is neither set nor inherited. A nested provider can pass one of them to reset that setting.Why?
A nested
ThemeProviderinherits 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 toADMIN_CONTENT_BACKGROUNDin@wordpress/admin-ui, which is still a second copy of a theme default. A plain "white" such as#fffis not a substitute: it flattens the generated neutral surfaces. Only@wordpress/themeknows its defaults, so it should publish them.How?
color={ { background: DEFAULT_THEME_SETTINGS.color.background } }resets only the background and keeps the inherited primary. Spreading the object resets everything.cornerRadiusfallback now reads the constant. The provider sets no cursor by default, socursor.controlrepeats the value of the--wpds-cursor-controltoken, and a test compares the two.edit-siteandbootuse it in place ofADMIN_CONTENT_BACKGROUND. They ship with the same@wordpress/theme, so they don't need a fallback.ADMIN_CONTENT_BACKGROUNDstays for scripts that bundle@wordpress/admin-uiand support older WordPress versions.wp.themeis a global that every script on the page shares.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.
bodybackground or to compare against.wp.theme.DEFAULT_THEME_SETTINGSisundefined. 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' } }).cursor.controlalready accepts'default'as a real value (the CSSdefaultcursor). The keyword is ambiguous there.'initial', as in CSS, avoids the clash.'default' | stringcollapses tostringin TypeScript.3. A separate prop (
inherit={ false },reset).#121514) with no error to explain them.reset={ [ 'background' ] }, which repeats the settings shape as a second API.isRootand the context in ways that need their own rules.4.
nullas an explicit reset (background: nullresets,undefinedinherits).string | null). Older WordPress treatsnullas omitted: no error, but the setting inherits, with the same result as a separate prop.nullandundefinedis easy to miss, andbackground: nullreads as "no background".5. Light and dark presets (
LIGHT_THEME,DARK_THEME).DEFAULT_THEME_SETTINGScovers the light case.ThemeProviderhas 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, …).?..7. Keep the value in
@wordpress/admin-uionly (#87839, now merged).admin-uiis bundled.Testing Instructions
/wp-admin/site-editor.php) with a non-default admin color scheme, for example Midnight.trunk./wp-admin/admin.php?page=site-editor-v2. The content area looks the same as ontrunk.wp.theme.DEFAULT_THEME_SETTINGSreturns the frozen object.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