Skip to content

fix: getChaiThemeCssVariables not generating correct variables code - #674

Merged
surajair merged 6 commits into
devfrom
673-getchaithemecssvariables-not-generating-correct-variables-code
Feb 5, 2026
Merged

surajair merged 6 commits into
devfrom
673-getchaithemecssvariables-not-generating-correct-variables-code

Conversation

@surajair

@surajair surajair commented Feb 4, 2026 •

Copy link
Copy Markdown
Collaborator

fix #673

@vercel

vercel Bot commented Feb 4, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
sdk Ready Ready Preview, Comment Feb 5, 2026 4:47am

Request Review

@surajair
surajair changed the base branch from main to dev February 4, 2026 14:01
@surajair surajair changed the title 673-getchaithemecssvariables-not-generating-correct-variables-code fix: getChaiThemeCssVariables not generating correct variables code Feb 4, 2026
@surajair
surajair requested a review from Copilot February 4, 2026 14:02
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Feb 4, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
❌ Deployment failed
View logs
sdk c9fa184 Feb 05 2026, 04:48 AM

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adjusts getChaiThemeCssVariables so it generates correct CSS variable strings instead of accidentally embedding boolean values when theme data is missing or optional flags are disabled.

Changes:

  • Wrap font-family variable generation in a ternary so that when fontVariables is false or theme.fontFamily is absent, an empty string is emitted instead of a boolean.
  • Wrap color variable generation for both :root and .dark themes in ternaries so missing chaiTheme.colors no longer results in false/undefined being stringified into the CSS.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@surajair

surajair commented Feb 4, 2026

Copy link
Copy Markdown
Collaborator Author

@copilot add unit tests
getChaiThemeCssVariables

Copilot AI commented Feb 4, 2026

Copy link
Copy Markdown
Contributor

@surajair I've opened a new pull request, #675, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 2 commits February 4, 2026 14:14
…comprehensive tests

Co-authored-by: surajair <9153560+surajair@users.noreply.github.com>
fix: prevent undefined/false literals in CSS output from getChaiThemeCssVariables

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

.join("\n ")
chaiTheme.colors
? Object.entries(chaiTheme.colors)
.map(([key, value]) => `--${key}: ${hexToHSL(value[1])};`)

Copilot AI Feb 5, 2026

Copy link

Choose a reason for hiding this comment

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

The implementation accesses value[1] to get the dark theme color, but there's no check to ensure that the second element exists in the color array. If a color tuple only contains one element (e.g., primary: ["#3b82f6"]), this would pass undefined to hexToHSL(), which would likely cause a runtime error.

Consider adding a check before accessing value[1], or falling back to value[0] if the dark theme color is not provided. For example: hexToHSL(value[1] || value[0]).

Suggested change
.map(([key, value]) => `--${key}: ${hexToHSL(value[1])};`)
.map(([key, value]) => `--${key}: ${hexToHSL(value[1] || value[0])};`)

Copilot uses AI. Check for mistakes.
Comment on lines +158 to +172
it("should handle partial colors (missing dark theme) gracefully", () => {
const theme: ChaiTheme = {
colors: {
primary: ["#3b82f6", "#1d4ed8"],
},
};

const result = getChaiThemeCssVariables({ theme });

// Should generate both light and dark sections
expect(result).toContain(":root");
expect(result).toContain(".dark");
// Should contain color variables in both sections
expect(result).toMatch(/--primary:\s*\d+\s+\d+%\s+\d+%;/);
});

Copilot AI Feb 5, 2026

Copy link

Choose a reason for hiding this comment

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

The test name says "partial colors (missing dark theme)" but the test data includes both light and dark colors in the tuple: primary: ["#3b82f6", "#1d4ed8"]. This test doesn't actually verify the behavior when the dark theme color is missing.

Consider either:

  1. Renaming the test to accurately reflect what it tests (e.g., "should handle theme with limited color palette")
  2. Modifying the test data to actually test the missing dark theme scenario (e.g., primary: ["#3b82f6"]), though this would likely expose the bug mentioned in the implementation where value[1] is accessed without checking if it exists.

Copilot uses AI. Check for mistakes.
@surajair
surajair merged commit a50fa62 into dev Feb 5, 2026
1 of 2 checks passed
@surajair
surajair deleted the 673-getchaithemecssvariables-not-generating-correct-variables-code branch February 5, 2026 04:46
surajair added a commit that referenced this pull request Feb 5, 2026

This branch was successfully deployed

1 active deployment
Preview — c9fa184e Deployed Feb 5, 2026 by vercel[bot]
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.

getChaiThemeCssVariables not generating correct variables code

3 participants