Skip to content

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
jaydeep-pipaliya:fix/oklch-hsl-color-conflict
Open

fix: use var() instead of hsl() wrapper when CSS vars contain OKLCH values#10264
jaydeep-pipaliya wants to merge 4 commits intoshadcn-ui:mainfrom
jaydeep-pipaliya:fix/oklch-hsl-color-conflict

Conversation

@jaydeep-pipaliya
Copy link
Copy Markdown

Summary

Fixes the color rendering failure when shadcn init generates OKLCH color variables in index.css but wraps them with hsl() in tailwind.config.js.

Root cause: buildTailwindThemeColorsFromCssVars() unconditionally wraps all CSS variable references with hsl() (e.g., hsl(var(--primary))). Since CLI 2.3.0 generates OKLCH values like oklch(0.205 0 0) in CSS variables, the hsl() 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 of hsl(var(--name)). Existing HSL-based themes continue to use hsl() wrapping for backward compatibility.

Before:

// tailwind.config.js (broken)
colors: { primary: { DEFAULT: 'hsl(var(--primary))' } }
// index.css: --primary: oklch(0.205 0 0);
// Result: hsl(oklch(0.205 0 0)) → invalid

After:

// tailwind.config.js (fixed)
colors: { primary: { DEFAULT: 'var(--primary)' } }
// index.css: --primary: oklch(0.205 0 0);
// Result: oklch(0.205 0 0) → correct

Fixes #10254

Test plan

  • Run npx shadcn@latest init in a fresh project
  • Verify tailwind.config.js uses var(--name) when CSS vars contain OKLCH values
  • Verify tailwind.config.js still uses hsl(var(--name)) for HSL-based themes
  • Verify theme colors render correctly in both OKLCH and HSL configurations
  • Run existing tests: pnpm test

…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
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Apr 2, 2026

@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.

Copy link
Copy Markdown
Collaborator

@shadcn shadcn left a comment

Choose a reason for hiding this comment

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

Can you add a test?

@jaydeep-pipaliya
Copy link
Copy Markdown
Author

Added tests in the latest commit covering all four cases:

  • OKLCH values → uses var(--name)
  • RGB values → uses var(--name)
  • Hex values → uses var(--name)
  • HSL values (existing behavior) → still uses hsl(var(--name))

All 1235 tests pass.

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.

[bug]: shadcn cli 2.3.0 init generates conflicting OKLCH CSS variables and HSL color wrapping causing color parsing failure

2 participants