Skip to content

fix: theme tokens and recipes that never reach apps - #54

Merged
aslamshah-hivemq merged 2 commits into
mainfrom
fix/theme-token-bugs
Oct 28, 2026
Merged

aslamshah-hivemq merged 2 commits into
mainfrom
fix/theme-token-bugs

Conversation

@aslamshah-hivemq

@aslamshah-hivemq aslamshah-hivemq commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Why

Several theme values are lost when the theme is merged with Chakra's defaultConfig. The source looks right, but apps never get them:

  • brand.muted dark is {colors.yellow.7 00}. The reference doesn't resolve, so there's no colour.
  • black.* / white.* alpha shades are dropped, because Chakra's single black / white value wins the merge. As a result bg.muted is broken in both modes.
  • bg / fg never override Chakra's in light mode. The theme writes them with base, and Chakra's _light value wins. In dark mode they worked until DEFAULT → default (feat: expand semantic tokens and add theme-lint enhancements #49) stopped the override.
  • Recipe keys Toast, Text and Heading are capitalised, but Chakra reads toast, text and heading, so none of them apply.
  • The mono font is 'IntelOne Mono', but @fontsource registers 'Intel One Mono'.

The design system site never showed these because it works around them. For example, its Toaster hand-sets colours on every toast, while apps rendering a plain <Toast.Root> get Chakra's default colours.

What

  • Fix the brand.muted reference. Move the alpha shades to Chakra's names, blackAlpha.* / whiteAlpha.*.
  • Add bg.DEFAULT (gray.50 / gray.950) and fg.DEFAULT (= content.primary), using _light so they win. bg.default stays as an alias.
  • Add bg.panel (white / gray.900) and put the line table rows on it, so cards, dialogs, menus and table rows stay one step off the page. Chakra's dark bg.panel is gray.950, which now matches the page.
  • Lowercase the recipe keys. Drop the base colour from text / heading; fg provides it, so text inside an Alert or Button keeps its parent's colour.
  • Rename the font to 'Intel One Mono'; theme-lint recognises both spellings.
  • Add system.test.ts, which builds the merged system and checks that every token ships as declared in both modes and that every recipe key is one Chakra reads. It fails on main.
  • Remove the matching workarounds from the design system site.

Visible changes in apps (no API breaks, but every app looks different):

  • Page background: white → gray.50 in light mode, and #09090B → gray.950 in dark mode, which is the biggest change.
  • Cards, dialogs, menus and table rows (bg.panel): gray.950 → gray.900 in dark mode. Table rows move from the page colour to white / gray.900.
  • Default text: near-black → gray.900 in light mode.
  • Tooltips (bg.inverted): near-black → gray.800 in light mode.
  • bg.muted, used by inputs, tracks, skeletons, tabs and tables: gray.100 → 8% black in light mode, and transparent → 8% white in dark mode.
  • Toasts: the theme colours replace Chakra's. ⚠️ The warning toast drops from 3.77:1 to 2.39:1, because warning.solid is lighter than Chakra's. Contrast of the solid colours will follow up in a separate PR after this PR is merged.
  • Code text: Intel One Mono instead of Menlo, where the font is installed.

Apps that override these tokens in their own theme keep their values. colors.black.* / colors.white.* become colors.blackAlpha.* / colors.whiteAlpha.*; the old names never resolved, so nothing breaks. Suggested release: 1.5.0, or 2.0.0 if visible default changes count as breaking.

Test plan

  • pnpm lint:all passes
  • tsc passes in theme and testing
  • pnpm test:unit passes (theme 55, site 116)
  • Checked the design system site in light and dark: backgrounds, bg.muted, brand.muted, mono font, real toasts

Screenshots

Before After
brand.muted (dark) before-brand-muted after-brand-muted
Warning toast, no hand-set colours before-warning-toast after-warning-toast

Several theme values were lost when merging with Chakra's defaultConfig:

- brand.muted dark referenced `yellow.7 00`, which never resolved
- black/white alpha shades were dropped by the merge with Chakra's single
  black/white values; they move to blackAlpha/whiteAlpha, fixing bg.muted
- bg/fg never overrode Chakra's: add bg.DEFAULT and fg.DEFAULT using
  _light so they win (bg.default kept as an alias)
- recipe keys Toast/Text/Heading were capitalised, so Chakra never read
  them; lowercase them and drop the base color from text/heading
- mono font renamed to 'Intel One Mono', the name @fontsource registers

Add a system test that builds the merged system and checks every token
ships as declared and every recipe key is one Chakra reads. Remove the
matching workarounds from the design system site.
@aslamshah-hivemq aslamshah-hivemq added the bug Something isn't working label Oct 21, 2026
// Same value as `bg`, kept for apps that already use it
default: { value: { _light: '{colors.gray.50}', _dark: '{colors.gray.950}' } },
inverted: { value: { _light: '{colors.gray.800}', _dark: '{colors.gray.100}' } },
muted: { value: { _light: '{colors.blackAlpha.200}', _dark: '{colors.whiteAlpha.200}' } },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

With bg now resolving to gray.50 / gray.950, Chakra's bg.panel (white / gray.950) ends up identical to the page background in dark mode, so cards, dialogs, menus etc. lose their contrast. Chakra's line table variant also puts rows on plain bg, so table rows blend into the page in both modes (checked against control-center-frontend, where all 32 tables use the default variant).

Could we add a panel token here so surfaces stay one step off the page?

Suggested change
muted: { value: { _light: '{colors.blackAlpha.200}', _dark: '{colors.whiteAlpha.200}' } },
muted: { value: { _light: '{colors.blackAlpha.200}', _dark: '{colors.whiteAlpha.200}' } },
// Surfaces that sit on the page (cards, dialogs, menus, table rows). Chakra's dark value is
// gray.950, the same as the page background, so surfaces would disappear in dark mode.
panel: { value: { _light: '{colors.white}', _dark: '{colors.gray.900}' } },

And in config.ts, point the line table rows at it so they no longer use the page background:

slotRecipes: {
  table: {
    slots: ['root', 'caption', 'header', 'body', 'footer', 'row', 'columnHeader', 'cell'],
    variants: {
      variant: {
        line: { row: { bg: 'bg.panel' } },
      },
    },
  },
  // ...
}

Light mode is unchanged for everything already on bg.panel (still white); dark mode shifts those surfaces from gray.950 to gray.900.

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.

Good catch, thanks. Before this PR the page was #09090B and panels gray.950, so this PR is what makes them collapse in dark mode. I've applied both suggestions in 63b7883. I checked that all dark text tokens stay ≥ 4.5:1 on gray.900, except secondary.fg (4.07), which the follow-up contrast PR fixes. One side effect: secondary.subtle in dark mode is also gray.900, so I'll move it off the panel colour in that PR.

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.

On reflection I'll leave secondary.subtle as is: text on it stays at 5.98:1, and the fill is only cosmetic. Listed as a known gap in the contrast PR.

@RobinAtherton
RobinAtherton self-requested a review October 21, 2026 13:50
With bg now resolving to gray.50 / gray.950, Chakra's bg.panel (white /
gray.950) matched the page in dark mode, so cards, dialogs and menus lost
their contrast. Add bg.panel (white / gray.900) and put the `line` table
rows on it instead of the page background.

@RobinAtherton RobinAtherton left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the panel token fixes and toasts, LGTM 🦕

@aslamshah-hivemq
aslamshah-hivemq merged commit 14dc8a9 into main Oct 28, 2026
5 checks passed
@aslamshah-hivemq
aslamshah-hivemq deleted the fix/theme-token-bugs branch October 28, 2026 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants