Skip to content

Commit 5299593

Browse files
committed
Fix cascade ordering for indexed theme lookups in inline path
The indexed lookup mixin (e.g. $colorMixins.backgroundColor[bg]) was placed before style functions added during attr processing, causing hover's `default: null` to override the mixin's backgroundColor. Changed from `afterBase: true` to `afterVariants: true` and added afterVariants handling in the inline rewrite-jsx path so these entries are appended last. https://claude.ai/code/session_01EhFJ4W5QixJn7ZLPzMbxPL
1 parent 96e19f4 commit 5299593

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/internal/lower-rules/value-patterns.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ export const createValuePatternHandlers = (ctx: ValuePatternContext) => {
665665
) as ExpressionKind;
666666

667667
decl.extraStylexPropsArgs ??= [];
668-
decl.extraStylexPropsArgs.push({ expr: indexedExpr, afterBase: true });
668+
decl.extraStylexPropsArgs.push({ expr: indexedExpr, afterVariants: true });
669669

670670
// Track in mixinOrder for correct cascade interleaving with extraStyleKeys
671671
const order = decl.mixinOrder ?? [];

src/internal/transform-steps/rewrite-jsx.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ export function rewriteJsxStep(ctx: TransformContext): StepResult {
404404
// Build interleaved extra args based on mixinOrder (if available)
405405
const extraMixinArgs: ExpressionKind[] = [];
406406
const extraAfterBaseArgs: ExpressionKind[] = [];
407+
const extraAfterVariantsArgs: ExpressionKind[] = [];
407408
if (mixinOrder && mixinOrder.length > 0) {
408409
let styleKeyIdx = 0;
409410
let propsArgIdx = 0;
@@ -426,7 +427,9 @@ export function rewriteJsxStep(ctx: TransformContext): StepResult {
426427
const arg = extraStylexPropsArgs[propsArgIdx];
427428
propsArgIdx++;
428429
if (arg) {
429-
if (arg.afterBase) {
430+
if (arg.afterVariants) {
431+
extraAfterVariantsArgs.push(arg.expr);
432+
} else if (arg.afterBase) {
430433
extraAfterBaseArgs.push(arg.expr);
431434
} else {
432435
extraMixinArgs.push(arg.expr);
@@ -437,7 +440,11 @@ export function rewriteJsxStep(ctx: TransformContext): StepResult {
437440
} else {
438441
// Fallback: no order tracking, use legacy behavior (propsArgs first, then styleKeys)
439442
for (const arg of extraStylexPropsArgs) {
440-
extraMixinArgs.push(arg.expr);
443+
if (arg.afterVariants) {
444+
extraAfterVariantsArgs.push(arg.expr);
445+
} else {
446+
extraMixinArgs.push(arg.expr);
447+
}
441448
}
442449
for (const key of extraStyleKeys) {
443450
const expr = j.memberExpression(
@@ -757,6 +764,9 @@ export function rewriteJsxStep(ctx: TransformContext): StepResult {
757764
styleAttr = null;
758765
}
759766

767+
// Append afterVariants entries last — they must override all variant/attr styles.
768+
styleArgs.push(...extraAfterVariantsArgs);
769+
760770
// Build extra className expression from CSS module classes (if any).
761771
const extraClassNameExpr =
762772
decl.extraClassNames && decl.extraClassNames.length > 0

test-cases/theme-indexedLookup.output.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ function Box(props: BoxProps) {
1616
<div
1717
sx={[
1818
styles.box,
19-
$colorMixins.backgroundColor[bg],
2019
styles.boxBackgroundColorHover(hoverColor),
20+
$colorMixins.backgroundColor[bg],
2121
]}
2222
>
2323
{children}

0 commit comments

Comments
 (0)