Skip to content

fix(utils): keep 0 alpha in oklchToCSS output - #9556

Open
Arunendra21 wants to merge 1 commit into
makeplane:previewfrom
Arunendra21:fix-oklch-zero-alpha
Open

fix(utils): keep 0 alpha in oklchToCSS output#9556
Arunendra21 wants to merge 1 commit into
makeplane:previewfrom
Arunendra21:fix-oklch-zero-alpha

Conversation

@Arunendra21

@Arunendra21 Arunendra21 commented Aug 6, 2026

Copy link
Copy Markdown

Bug

oklchToCSS (packages/utils/src/theme/color-conversion.ts) appends the alpha channel only when alpha is truthy:

`...${alpha ? ` / ${alpha.toFixed(2)}%` : ""})`

Because 0 is falsy, an alpha of 0 (fully transparent) is dropped and the colour renders opaque instead of transparent:

oklchToCSS({ l: 0.5, c: 0.1, h: 250 }, 0)
// before: "oklch(0.5000 0.1000 250.00)"        // opaque
// after:  "oklch(0.5000 0.1000 250.00 / 0.00%)" // transparent

This is reachable via theme-application.ts, which builds the --alpha-white-* / --alpha-black-* tokens with oklchToCSS(neutralOKLCH, value * 100) — a 0 alpha token would come out opaque.

Fix

Guard with alpha != null so 0 is emitted while an omitted alpha still produces no alpha channel. Verified against alpha = 0, a positive alpha, and an omitted alpha. (packages/utils has no unit-test runner configured, so no test file is included.)

Summary by CodeRabbit

  • Bug Fixes
    • Corrected color formatting so fully transparent colors retain their alpha value in CSS output.

oklchToCSS appended the alpha channel only when `alpha` was truthy, so an
alpha of 0 (fully transparent) was dropped and the colour rendered
opaque. This affects the alpha theme tokens generated in
theme-application.ts, where alpha is passed as `value * 100`. Guard with
`alpha != null` so 0 is emitted as `/ 0.00%` while an omitted alpha still
produces no alpha channel.

Co-authored-by: eeshsaxena <eeshsaxena@gmail.com>
@CLAassistant

CLAassistant commented Aug 6, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c7e3508d-c971-4c92-9806-881aa5b08aa5

📥 Commits

Reviewing files that changed from the base of the PR and between 31853ab and 9614977.

📒 Files selected for processing (1)
  • packages/utils/src/theme/color-conversion.ts

📝 Walkthrough

Walkthrough

oklchToCSS now includes alpha: 0 in the generated CSS output. It still omits the alpha component when alpha is null or undefined.

Changes

Color conversion

Layer / File(s) Summary
Alpha formatting
packages/utils/src/theme/color-conversion.ts
The alpha suffix condition now uses a nullish check. Zero alpha values are emitted.

Estimated code review effort: 1 (Trivial) | ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the utility, the alpha-zero bug, and the intended output behavior.
Description check ✅ Passed The description explains the bug, demonstrates the before-and-after behavior, identifies the affected path, and records verification scenarios.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

2 participants