Skip to content

Commit 238289a

Browse files
fix: use var() instead of hsl() wrapper when CSS vars contain OKLCH values
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 #10254
1 parent 5a67028 commit 238289a

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

packages/shadcn/src/utils/updaters/update-tailwind-config.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -506,30 +506,43 @@ export function buildTailwindThemeColorsFromCssVars(
506506
) {
507507
const result: Record<string, any> = {}
508508

509+
// When CSS variables use oklch(), rgb(), or hex values, reference them
510+
// directly via var() instead of wrapping with hsl().
511+
const hasNonHSLValues = Object.values(cssVars).some(
512+
(value) =>
513+
typeof value === "string" &&
514+
(value.startsWith("oklch") ||
515+
value.startsWith("rgb") ||
516+
value.startsWith("#"))
517+
)
518+
519+
const wrapVar = (varName: string) =>
520+
hasNonHSLValues ? `var(--${varName})` : `hsl(var(--${varName}))`
521+
509522
for (const key of Object.keys(cssVars)) {
510523
const parts = key.split("-")
511524
const colorName = parts[0]
512525
const subType = parts.slice(1).join("-")
513526

514527
if (subType === "") {
515528
if (typeof result[colorName] === "object") {
516-
result[colorName].DEFAULT = `hsl(var(--${key}))`
529+
result[colorName].DEFAULT = wrapVar(key)
517530
} else {
518-
result[colorName] = `hsl(var(--${key}))`
531+
result[colorName] = wrapVar(key)
519532
}
520533
} else {
521534
if (typeof result[colorName] !== "object") {
522-
result[colorName] = { DEFAULT: `hsl(var(--${colorName}))` }
535+
result[colorName] = { DEFAULT: wrapVar(colorName) }
523536
}
524-
result[colorName][subType] = `hsl(var(--${key}))`
537+
result[colorName][subType] = wrapVar(key)
525538
}
526539
}
527540

528541
// Remove DEFAULT if it's not in the original cssVars
529542
for (const [colorName, value] of Object.entries(result)) {
530543
if (
531544
typeof value === "object" &&
532-
value.DEFAULT === `hsl(var(--${colorName}))` &&
545+
value.DEFAULT === wrapVar(colorName) &&
533546
!(colorName in cssVars)
534547
) {
535548
delete value.DEFAULT

0 commit comments

Comments
 (0)