fix(react-ui): stop false "unknown key" warnings for valid *ChartPalette theme keys#715
Open
ankit-thesys wants to merge 1 commit into
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #714 · Linear: TH-2186
Summary
createTheme({ defaultChartPalette: [...] })onlightTheme/darkTheme— compiled fine but warnedunknown key … It will be ignoredtwice per key on every dev boot. The message was false: the theme merge spreads user overrides wholesale, so palettes were reachinguseTheme()and charts were applying them all along. Root cause: both validators derived their allow-list fromObject.keys(defaultLightTheme), which defines none of the eight*ChartPalettekeys declared on theThemetype (types-vs-runtime drift).KNOWN_THEME_KEYS= default theme keys +CHART_PALETTE_KEYS) consumed by bothcreateTheme()and the ThemeProvider prop validator.CHART_PALETTE_KEYSis guarded bysatisfies 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 indefaultTheme.ts— a default would shadow the per-chartthemeprop fallback inuseChartPalette, andthemeToCssVars's string-only filter means palettes never belonged in CSS vars anyway.ThemeProvider/__tests__/ThemeProvider.test.tsx) +tsconfig.test.json(required by the ESLint override for__tests__files, mirroring react-headless). Updated the ThemeProviderAGENTS.mdwith the palette-key exception to the "adding a new token" recipe.Investigation findings (verified against
main)default/bar/line/area/pie/radar/radial/horizontalBar), not 5 as first reportedObject.keys(defaultLightTheme)ThemeProvider.tsx:112,utils.ts:70); consumers usingcreateThemegot warned twice per keyThemeProvider → useTheme() → useChartPaletteshowed palettes survive the merge ({ ...themes.dark, ...overrides }) and drive chart colors, incl. fallback todefaultChartPalettefor unset chart typescustomPaletteworkaroundsIs the problem gone?
Yes — re-ran the exact pre-fix reproduction probe against this branch:
theme.barChartPalettein contextdefaultChartPalete)defaultChartPaletteTest plan
pnpm --filter @openuidev/react-ui run test— 13/13 pass (7 new: allow-list covers every declared palette key + every default-theme key;createThemesilent for all 8 palette keys; ThemeProvider props silent for palette keys; genuine unknown keys still warn with suggestion; palettes flow theme →useTheme()→useChartPaletteincl.defaultChartPalettefallback)pnpm --filter @openuidev/react-ui run typecheck— cleanpnpm --filter @openuidev/react-ui run lint:check— 0 errors (pre-existing warnings only)pnpm --filter @openuidev/react-ui run format:check— cleanMade with Cursor