-
-
Notifications
You must be signed in to change notification settings - Fork 455
fix: css variable parsing #223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: 0xdhrv <19857414+0xdhrv@users.noreply.github.com>
…-e4dee7c54ff3 Fix CSS variable parsing: skip var() references to prevent UI breakage
@0xdhrv is attempting to deploy a commit to the tweakcn OSS program Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughAdded a guard in Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Caller
participant Parser as parseColorVariables
participant Logger as Logger
participant Proc as processColorValue
participant Fmt as colorFormatter
Caller->>Parser: parseColorVariables(input)
loop for each color entry
alt cleaned value starts with "var(" and ends with ")"
Parser->>Logger: warn("Skipping CSS variable color value")
note right of Parser #DDEBF7: CSS variable reference skipped
else
Parser->>Proc: processColorValue(trimmedValue)
Proc-->>Parser: processedColor
Parser->>Fmt: colorFormatter(processedColor)
Fmt-->>Parser: formattedColor
Parser-->>Caller: assign to ThemeStyleProps
end
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate 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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
utils/parse-css-input.ts
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Vercel Agent Review
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
utils/parse-css-input.ts
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Vercel Agent Review
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
utils/parse-css-input.ts (1)
58-66
: Harden detection: skip whenvar(
appears anywhere and strip block comments first.Prevents crashes for values like
color-mix(..., var(--x), ...)
orvar(--x) /*comment*/
where the currentstartsWith/endsWith
check won’t catch it. Also ensures comments don’t leak into the color parser.Apply this diff:
- const valueWithoutImportant = trimmedValue.replace(/\s*!important$/i, ""); + const valueWithoutImportant = trimmedValue.replace(/\s*!important$/i, ""); + const valueWithoutComments = valueWithoutImportant.replace(/\/\*[\s\S]*?\*\//g, "").trim(); - // Skip CSS variable references (var(...)) as they can't be processed as colors - if ( - valueWithoutImportant.toLowerCase().startsWith("var(") && - valueWithoutImportant.endsWith(")") - ) { + // Skip if any CSS variable reference is present; color parsing would be unreliable + if (/\bvar\s*\(/i.test(valueWithoutComments)) { console.warn(`Skipping CSS variable reference: ${cleanName}: ${trimmedValue}`); return; } - const colorValue = processColorValue(valueWithoutImportant); + const colorValue = processColorValue(valueWithoutComments);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
utils/parse-css-input.ts
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Vercel Agent Review
🔇 Additional comments (1)
utils/parse-css-input.ts (1)
55-67
: LGTM: normalization + guard are correct, and cleaned value is used.Trimming, stripping
!important
, skippingvar(...)
, and passing the cleaned value intoprocessColorValue
address the crash path and prior feedback.
This pull request introduces an improvement to the
parseColorVariables
function inutils/parse-css-input.ts
to handle CSS variable references more robustly. The main change is the addition of logic to skip CSS variable references (e.g.,var(--color-primary)
) during color parsing, preventing errors and ensuring only actual color values are processed.Color variable parsing improvements:
parseColorVariables
to detect and skip CSS variable references (var(...)
), logging a warning when encountered, so only valid color values are processed.Summary by CodeRabbit