Skip to content

fix(react-ui): stop false "unknown key" warnings for valid *ChartPalette theme keys#715

Open
ankit-thesys wants to merge 1 commit into
mainfrom
ankit/th-2186-themeprovider-falsely-warns-unknown-key-it-will-be-ignored
Open

fix(react-ui): stop false "unknown key" warnings for valid *ChartPalette theme keys#715
ankit-thesys wants to merge 1 commit into
mainfrom
ankit/th-2186-themeprovider-falsely-warns-unknown-key-it-will-be-ignored

Conversation

@ankit-thesys

Copy link
Copy Markdown
Contributor

Fixes #714 · Linear: TH-2186

Summary

  • Theming charts the typed way — createTheme({ defaultChartPalette: [...] }) on lightTheme/darkTheme — compiled fine but warned unknown key … It will be ignored twice per key on every dev boot. The message was false: the theme merge spreads user overrides wholesale, so palettes were reaching useTheme() and charts were applying them all along. Root cause: both validators derived their allow-list from Object.keys(defaultLightTheme), which defines none of the eight *ChartPalette keys declared on the Theme type (types-vs-runtime drift).
  • Fix: one shared allow-list (KNOWN_THEME_KEYS = default theme keys + CHART_PALETTE_KEYS) consumed by both createTheme() and the ThemeProvider prop validator. CHART_PALETTE_KEYS is guarded by satisfies Record<keyof ChartColorPalette, true>, so adding/removing a palette key on the type without updating the allow-list is now a compile error. Deliberately no palette defaults in defaultTheme.ts — a default would shadow the per-chart theme prop fallback in useChartPalette, and themeToCssVars's string-only filter means palettes never belonged in CSS vars anyway.
  • Added regression tests (ThemeProvider/__tests__/ThemeProvider.test.tsx) + tsconfig.test.json (required by the ESLint override for __tests__ files, mirroring react-headless). Updated the ThemeProvider AGENTS.md with the palette-key exception to the "adding a new token" recipe.

Investigation findings (verified against main)

Claim Verdict
Type declares palette keys, validators reject them Confirmed — but it's 8 keys (default/bar/line/area/pie/radar/radial/horizontalBar), not 5 as first reported
Both validators use Object.keys(defaultLightTheme) Confirmed (ThemeProvider.tsx:112, utils.ts:70); consumers using createTheme got warned twice per key
"It will be ignored" False — runtime probe through real ThemeProvider → useTheme() → useChartPalette showed palettes survive the merge ({ ...themes.dark, ...overrides }) and drive chart colors, incl. fallback to defaultChartPalette for unset chart types
Severity Dev-only misleading noise — but it drove a downstream consumer to abandon theme-level palettes for per-chart customPalette workarounds

Is the problem gone?

Yes — re-ran the exact pre-fix reproduction probe against this branch:

Before (main) After (this PR)
Warnings on mount 6 (2 per palette key) 0
theme.barChartPalette in context present present (unchanged)
Chart colors from theme palette applied applied (unchanged)
Typo detection (defaultChartPalete) warns still warns, now suggests defaultChartPalette

Test plan

  • pnpm --filter @openuidev/react-ui run test — 13/13 pass (7 new: allow-list covers every declared palette key + every default-theme key; createTheme silent for all 8 palette keys; ThemeProvider props silent for palette keys; genuine unknown keys still warn with suggestion; palettes flow theme → useTheme()useChartPalette incl. defaultChartPalette fallback)
  • pnpm --filter @openuidev/react-ui run typecheck — clean
  • pnpm --filter @openuidev/react-ui run lint:check — 0 errors (pre-existing warnings only)
  • pnpm --filter @openuidev/react-ui run format:check — clean
  • Pre-fix repro probe re-run on branch: zero warnings, palettes still applied (table above)

Made with Cursor

…eme keys

The Theme type declares eight *ChartPalette keys, but both theme validators
derived their allow-list from Object.keys(defaultLightTheme), which defines
none of them - so the typed chart-theming API warned "unknown key ... It will
be ignored" on every dev boot (twice per key), even though the palettes flow
through the merge and charts apply them.

Both validators now share one allow-list (default theme keys + a
CHART_PALETTE_KEYS constant guarded by `satisfies Record<keyof
ChartColorPalette, true>`), so type/runtime drift is a compile error.
Regression tests cover the allow-list, warning behavior, and palette flow.

Fixes #714

Co-authored-by: Cursor <cursoragent@cursor.com>
@ankit-thesys ankit-thesys self-assigned this Jul 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ThemeProvider falsely warns "unknown key — it will be ignored" for valid *ChartPalette theme keys

1 participant