Skip to content

Commit c7d41ec

Browse files
skovhusclaude
andcommitted
fix(cssHelper): narrow background→backgroundColor to ConditionalExpression only
The previous check used `condition === "always"` which also matches destructured defaults (e.g. `({ bg = "url(...)" }) => background: ${bg}`). Adding a `callArg.type === "ConditionalExpression"` guard ensures only theme-resolved conditionals (where both branches are color tokens) get the backgroundColor conversion. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 02da5b4 commit c7d41ec

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/internal/lower-rules/template-literals.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,10 +491,17 @@ export function resolveTemplateLiteralBranch(
491491
});
492492
continue;
493493
}
494-
// Handle `background: ${expr}` shorthand → backgroundColor dynamic entry
495-
// Only apply when the expression is a theme-based resolution (condition: "always"),
496-
// not for simple prop passthroughs (e.g. background: ${props.background}).
497-
if (propName === "background" && !prefix && !suffix && resolved.condition === "always") {
494+
// Handle `background: ${expr}` shorthand → backgroundColor dynamic entry.
495+
// Only apply for theme-resolved conditionals (ConditionalExpression with condition: "always"),
496+
// where both branches are theme color tokens. Destructured defaults also set condition: "always"
497+
// but produce Identifier/other node types and may carry non-color values (gradients, images).
498+
if (
499+
propName === "background" &&
500+
!prefix &&
501+
!suffix &&
502+
resolved.condition === "always" &&
503+
resolved.callArg.type === "ConditionalExpression"
504+
) {
498505
dynamicEntries.push({
499506
jsxProp: resolved.jsxProp,
500507
stylexProp: "backgroundColor",

0 commit comments

Comments
 (0)