Skip to content

[FIX] [V2] Conditional expressions in Babel Plugin's content retrieval#1241

Merged
cdn34dd merged 1 commit intofeature/v2from
carlosnogueira/issue-1238/babel-fix-jsx-conditionals-v2
Apr 9, 2026
Merged

[FIX] [V2] Conditional expressions in Babel Plugin's content retrieval#1241
cdn34dd merged 1 commit intofeature/v2from
carlosnogueira/issue-1238/babel-fix-jsx-conditionals-v2

Conversation

@cdn34dd
Copy link
Copy Markdown
Contributor

@cdn34dd cdn34dd commented Apr 7, 2026

What does this PR do?

Fix raw JSX in getContent closure for conditional expressions, by adding ConditionalExpression and LogicalExpression handlers to recursively convert JSX inside expression branches.

Motivation

Issue #1238.

Additional Notes

Anything else we should know when reviewing?

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)
  • If this PR is auto-generated, please make sure also to manually update the code related to the change

@cdn34dd cdn34dd requested a review from a team as a code owner April 7, 2026 16:12
Copilot AI review requested due to automatic review settings April 7, 2026 16:12
Copy link
Copy Markdown

Copilot AI left a comment

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 fixes a bug where conditional JSX expressions (ternary operators and logical operators) inside Pressable components with useCallback handlers were emitted as raw JSX in the bundle, causing Hermes compilation failures. The fix adds recursive processing and dedicated handlers for ConditionalExpression and LogicalExpression AST nodes in the jsxChildToRuntimeCall function, ensuring all JSX within conditional branches is properly converted to jsx() runtime calls.

Changes:

  • Added ConditionalExpression handler to recursively convert JSX in both branches of ternary expressions
  • Added LogicalExpression handler to recursively convert JSX in the right operand of logical operators
  • Modified JSXExpressionContainer handling to recursively process inner expressions instead of directly cloning them
  • Added comprehensive test cases covering ternary operators, logical operators, nested conditionals, and the useCallback scenario from the issue

Reviewed changes

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

File Description
packages/react-native-babel-plugin/src/actions/rum/index.ts Modified jsxChildToRuntimeCall function to recursively handle conditional and logical expressions containing JSX
packages/react-native-babel-plugin/test/plugin.test.ts Added 5 new test cases validating JSX conversion in conditional expression contexts

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

@cdn34dd cdn34dd force-pushed the carlosnogueira/issue-1238/babel-fix-jsx-conditionals-v2 branch from 38875c0 to 713c88a Compare April 9, 2026 09:27
@cdn34dd cdn34dd merged commit c3246ce into feature/v2 Apr 9, 2026
9 checks passed
@cdn34dd cdn34dd deleted the carlosnogueira/issue-1238/babel-fix-jsx-conditionals-v2 branch April 9, 2026 10:21
@sbarrio sbarrio mentioned this pull request Apr 14, 2026
4 tasks
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