Skip to content

Commit a200066

Browse files
committed
Clarify sx prop fallback comments based on compiler analysis
The StyleX compiler's sx→stylex.props transformation works unconditionally; the hasLocalStyleRef check is an optimization (avoids unnecessary intermediate rewrite when the compiler would bail to runtime anyway), not a correctness fix. https://claude.ai/code/session_01EhFJ4W5QixJn7ZLPzMbxPL
1 parent 5299593 commit a200066

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

src/internal/emit-wrappers/style-merger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ export function emitStyleMerging(args: {
175175
) {
176176
// When useSxProp is enabled, emit sx={expr} instead of {...stylex.props(expr)}
177177
// Only valid on intrinsic elements (the StyleX babel plugin only processes lowercase tags).
178-
// sx requires at least one local styles.* reference for the compiler to recognize;
179-
// fall back to stylex.props() when all styles are external (e.g. mixin map lookups).
178+
// Prefer sx only when local styles.* references exist; when all styles are external
179+
// the compiler bails out of static compilation, so emit stylex.props() directly.
180180
const sid = emitter.stylesIdentifier;
181181
const hasLocalRef = styleArgs.some((a) => j([a]).find(j.Identifier, { name: sid }).size() > 0);
182182
if (emitter.useSxProp && isIntrinsicElement && hasLocalRef) {

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -793,9 +793,10 @@ export function rewriteJsxStep(ctx: TransformContext): StepResult {
793793
}
794794

795795
const needsMerge = effectiveClassNameAttr !== null || styleAttr !== null;
796-
// sx prop requires at least one local stylex.create() reference so the
797-
// StyleX compiler can verify and transform it. When all styles are external
798-
// (e.g. only extraStylexPropsArgs mixin lookups), fall back to stylex.props().
796+
// Prefer sx prop only when local stylex.create() references exist. When all
797+
// styles are external (e.g. only mixin map lookups), the compiler bails out
798+
// of static compilation and leaves stylex.props() as a runtime call anyway.
799+
// Emitting stylex.props() directly avoids the unnecessary sx→stylex.props rewrite.
799800
const stylesId = ctx.stylesIdentifier ?? "styles";
800801
const hasLocalStyleRef = styleArgs.some(
801802
(arg) => j([arg]).find(j.Identifier, { name: stylesId }).size() > 0,

0 commit comments

Comments
 (0)