fix: use var() instead of hsl() wrapper when CSS vars contain OKLCH values#10264
Open
jaydeep-pipaliya wants to merge 4 commits intoshadcn-ui:mainfrom
Open
fix: use var() instead of hsl() wrapper when CSS vars contain OKLCH values#10264jaydeep-pipaliya wants to merge 4 commits intoshadcn-ui:mainfrom
jaydeep-pipaliya wants to merge 4 commits intoshadcn-ui:mainfrom
Conversation
…alues buildTailwindThemeColorsFromCssVars() unconditionally wrapped all CSS variable references with hsl(), but the CLI now generates OKLCH color values in index.css. This caused a format conflict where hsl(var(--primary)) tried to interpret oklch(0.205 0 0) as HSL. Detect whether the CSS variables contain non-HSL values (oklch, rgb, hex) and reference them directly via var(--name) instead of wrapping with hsl(). Existing HSL-based themes continue to use hsl(var(--name)) for backward compatibility. Fixes shadcn-ui#10254
Contributor
|
@jaydeep-pipaliya is attempting to deploy a commit to the shadcn-pro Team on Vercel. A member of the Team first needs to authorize it. |
…hemeColorsFromCssVars
Author
|
Added tests in the latest commit covering all four cases:
All 1235 tests pass. |
2 tasks
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.
Summary
Fixes the color rendering failure when
shadcn initgenerates OKLCH color variables inindex.cssbut wraps them withhsl()intailwind.config.js.Root cause:
buildTailwindThemeColorsFromCssVars()unconditionally wraps all CSS variable references withhsl()(e.g.,hsl(var(--primary))). Since CLI 2.3.0 generates OKLCH values likeoklch(0.205 0 0)in CSS variables, thehsl()wrapper tries to interpret OKLCH as HSL, causing colors to fail.Fix: Detect whether the CSS variables contain non-HSL color values (oklch, rgb, hex). When they do, reference them directly via
var(--name)instead ofhsl(var(--name)). Existing HSL-based themes continue to usehsl()wrapping for backward compatibility.Before:
After:
Fixes #10254
Test plan
npx shadcn@latest initin a fresh projecttailwind.config.jsusesvar(--name)when CSS vars contain OKLCH valuestailwind.config.jsstill useshsl(var(--name))for HSL-based themespnpm test