Skip to content

Boot: Wire user admin theme preference to ThemeProvider#74011

Merged
aduth merged 6 commits intotrunkfrom
add/theme-boot-user-pref
Dec 16, 2025
Merged

Boot: Wire user admin theme preference to ThemeProvider#74011
aduth merged 6 commits intotrunkfrom
add/theme-boot-user-pref

Conversation

@aduth
Copy link
Member

@aduth aduth commented Dec 15, 2025

What?

Updates boot screens to initialize ThemeProvider using the user's color preference, extracted from the document body's admin-theme-* class.

Includes a supporting change to expose ThemeProvider TypeScript type from the package, which ensures that the component is still private, but its types are available (e.g. as used to inherit props for UserThemeProvider wrapper).

Related discussion: #69130 (comment)

Why?

  • Ensures that the user's selected color preference is respected on these new screens.
  • Helps validate the implementation of color theming and its built-in backwards-compatibility for initializing CSS properties like --wp-admin-theme-color.

How?

Creates a new UserThemeProvider component in the boot package, which wraps ThemeProvider and maps the admin body class to the expected primary seed value.

This follows from how base-styles maps admin schemes to equivalent seed colors (source).

Testing Instructions

Prerequisite: Use a user theme other than the default:

  1. Go to Users > Profile
  2. Pick an "Administration Color Scheme" other than "Default", e.g. "Ectoplasm"

Verify that the Fonts page respects the configured color theme:

  1. Go to Appearance > Fonts
  2. Color accent should follow from the configured user preference. You should see it take effect in tabs border underline and the button in the bottom-right (see screenshot below)

Screenshots or screencast

Before After
Screenshot 2025-12-15 at 3 16 52 PM Screenshot 2025-12-15 at 3 16 44 PM

@aduth aduth requested a review from a team as a code owner December 15, 2025 20:24
@github-actions
Copy link

github-actions bot commented Dec 15, 2025

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 props-bot label.

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: aduth <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: youknowriad <[email protected]>

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

@aduth aduth added [Type] Task Issues or PRs that have been broken down into an individual action to take [Package] Theme /packages/theme [Package] Boot /packages/boot labels Dec 15, 2025
@github-actions
Copy link

Flaky tests detected in 5037b7f.
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.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/20246455195
📝 Reported issues:

Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@youknowriad
Copy link
Contributor

Is the body class expected to be present in all WP-Admin pages?

@t-hamano
Copy link
Contributor

Is the body class expected to be present in all WP-Admin pages?

I think so. If we have a screen that doesn't have that body class, I think we should add it.

I just committed a fix related to this to core today: https://core.trac.wordpress.org/changeset/61385

Comment on lines +10 to +26
const THEME_PRIMARY_COLORS = new Map< string, string >( [
[ 'light', '#0085ba' ],
[ 'modern', '#3858e9' ],
[ 'blue', '#096484' ],
[ 'coffee', '#46403c' ],
[ 'ectoplasm', '#523f6d' ],
[ 'midnight', '#e14d43' ],
[ 'ocean', '#627c83' ],
[ 'sunrise', '#dd823b' ],
] );

export function getAdminThemePrimaryColor(): string | undefined {
const theme =
document.body.className.match( /admin-color-([a-z]+)/ )?.[ 1 ];

return theme && THEME_PRIMARY_COLORS.get( theme );
}
Copy link
Member Author

@aduth aduth Dec 16, 2025

Choose a reason for hiding this comment

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

I pushed a small micro-optimization / code simplification in 883a400 . I think it reads a bit better and is ~1.7x faster.

map x 281,001,631 ops/sec ±5.77% (74 runs sampled)
switch x 167,011,358 ops/sec ±3.54% (87 runs sampled)
Fastest is map
Benchmark code
import Benchmark from "benchmark";

const suite = new Benchmark.Suite();

const theme = "coffee";

const MAPPING = new Map([
  ["light", "#0085ba"],
  ["modern", "#3858e9"],
  ["blue", "#096484"],
  ["coffee", "#46403c"],
  ["ectoplasm", "#523f6d"],
  ["midnight", "#e14d43"],
  ["ocean", "#627c83"],
  ["sunrise", "#dd823b"],
]);

function getThemeSwitch(theme) {
  switch (theme) {
    case "light":
      return "#0085ba";
    case "modern":
      return "#3858e9";
    case "blue":
      return "#096484";
    case "coffee":
      return "#46403c";
    case "ectoplasm":
      return "#523f6d";
    case "midnight":
      return "#e14d43";
    case "ocean":
      return "#627c83";
    case "sunrise":
      return "#dd823b";
  }

  return undefined;
}

function getThemeMap(theme) {
  return theme && MAPPING.get(theme);
}

suite.add("map", (event) => {
  getThemeMap(theme);
});

suite.add("switch", async () => {
  getThemeSwitch(theme);
});

suite
  .run({ async: true })
  .on("cycle", (event) => {
    console.log(String(event.target));
  })
  .on("complete", () => {
    console.log("Fastest is " + suite.filter("fastest").map("name"));
  });

@aduth aduth merged commit bf3ccec into trunk Dec 16, 2025
36 of 37 checks passed
@aduth aduth deleted the add/theme-boot-user-pref branch December 16, 2025 18:12
@github-actions github-actions bot added this to the Gutenberg 22.4 milestone Dec 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Boot /packages/boot [Package] Theme /packages/theme [Type] Task Issues or PRs that have been broken down into an individual action to take

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants