Skip to content

Conversation

@mathpirate
Copy link
Contributor

@mathpirate mathpirate commented Dec 3, 2025

Changes the decision logic for when to use when/unless helpers:

  • Previously based on whether LEFT side was a simple opaque ref access
  • Now based on whether RIGHT side is "expensive" (JSX or needs derive)

This better captures the intent: when/unless provide short-circuit optimization that's most valuable when the right side is expensive to construct (like JSX) or when both sides need derive (for taint tracking).

Key changes:

  • Add isJsxExpression() helper to detect JSX elements/fragments
  • Use when/unless only when: rightIsJsx OR rightNeedsDerive
  • Simple refs passed directly to when/unless (no derive wrapper)
  • String/number literals on right side → plain derive, no short-circuit

Summary by cubic

Optimized when/unless usage to only short-circuit when the right-hand side is expensive (JSX or needs derive), reducing unnecessary derive wrapping and matching actual runtime cost.

  • Refactors
    • Added isJsxExpression() to detect JSX elements and fragments.
    • Use when/unless only when the right side is JSX or has reactive deps; otherwise wrap the whole expression in derive.
    • Pass simple opaque refs directly as the condition; derive complex left conditions when needed.
    • Keep string/number literals on the right inside derive (no short-circuit).
    • Avoid re-wrapping when/unless/computed calls in derive.
    • Updated fixtures and tests for &&, ||, ?? chains and map callbacks to reflect the new selection logic.

Written for commit 070b7b2. Summary will update automatically on new commits.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 10 files

} as const satisfies __ctHelpers.JSONSchema, true as const satisfies __ctHelpers.JSONSchema, { item: {
name: item.name
} }, ({ item }) => item.name && <span>{item.name}</span>)}
} }, ({ item }) => __ctHelpers.when(item.name, <span>{item.name}</span>))}
Copy link
Contributor

Choose a reason for hiding this comment

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

this is called from within a derive here? that's a bit redundant taint-wise * uncomplicating jsx. i wonder what triggered that.

@mathpirate mathpirate force-pushed the gideon/when-unless-jsx-optimization branch from 58fd12d to 4e16ddb Compare December 4, 2025 23:25
@mathpirate mathpirate force-pushed the gideon/when-unless-jsx-optimization branch from 4e16ddb to 37becef Compare December 5, 2025 00:06
@mathpirate mathpirate force-pushed the gideon/when-unless-jsx-optimization branch from 37becef to 060b20b Compare December 8, 2025 19:43
@mathpirate mathpirate force-pushed the gideon/when-unless-jsx-optimization branch from 060b20b to 4e03a45 Compare December 10, 2025 02:02
mathpirate and others added 3 commits December 10, 2025 22:47
Changes the decision logic for when to use `when`/`unless` helpers:
- Previously based on whether LEFT side was a simple opaque ref access
- Now based on whether RIGHT side is "expensive" (JSX or needs derive)

This better captures the intent: when/unless provide short-circuit
optimization that's most valuable when the right side is expensive
to construct (like JSX) or when both sides need derive (for taint
tracking).

Key changes:
- Add isJsxExpression() helper to detect JSX elements/fragments
- Use when/unless only when: rightIsJsx OR rightNeedsDerive
- Simple refs passed directly to when/unless (no derive wrapper)
- String/number literals on right side → plain derive, no short-circuit

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@mathpirate mathpirate force-pushed the gideon/when-unless-jsx-optimization branch from 3c3fa81 to 070b7b2 Compare December 11, 2025 06:47
@mathpirate mathpirate merged commit 03197d2 into main Dec 15, 2025
9 checks passed
@mathpirate mathpirate deleted the gideon/when-unless-jsx-optimization branch December 15, 2025 22:59
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.

3 participants