Skip to content

Evaluate JSX children after the other props in plain mode - #9117

Merged
cknitt merged 1 commit into
masterfrom
fix-9104-jsx-eval-order
Oct 29, 2026
Merged

cknitt merged 1 commit into
masterfrom
fix-9104-jsx-eval-order

Conversation

@cknitt

@cknitt cknitt commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Plain and preserve JSX mode evaluated the parts of an element in different orders. Plain mode built the props record in the declaration order of its type, and JsxDOM.domProps declares children second, so <div title={t()}> {c()} </div> evaluated c before t; preserve mode emits JSX, where the children come after the attributes and are evaluated last. The same held for any component whose props type declares children before other fields.

Plain mode now goes through the same Pjsx element as preserve mode (which already put the children after the other props) and prints it as the call, so both modes evaluate tag, spread, props, children and key in the same order by construction. In plain mode the object literal now lists children last. Two things that were only right for preserve mode are now limited to it: keeping a tag like M.make unflattened (the passes in lam_pass_remove_alias and js_pass_flatten_and_mark_dead). And Lam_util.refine_let no longer substitutes a let-bound tag into an element whose only argument is the tag, which would inline a function literal and drop the name let make = … gives it (React shows that name); the old call always had a props argument, so it never hit that rule.

Tests:

  • tests/build_tests/jsx_preserve_semantics/cases/Order.res logs children against an attribute and the key for a DOM element, for a component whose props type declares children first, and for several children (jsxs). The suite compares plain mode with preserve mode compiled by TypeScript, and fails on master.
  • tests/tests/src/jsx_children_order_test.res shows the plain-mode output with children last.
  • tests/gentype_tests/typescript-react-example/src/Hooks.res.js changes only in the position of children in props objects.

Evaluation order: plain mode now follows preserve mode / JSX source order (attributes, then children, then the key), rather than preserve mode following the props type's declaration order, which JSX can only express by writing children as a children={…} attribute. Attributes among themselves are still evaluated in the props type's declaration order in both modes, as before.

Fixes #9104

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kbf3gGkPma9LAZimuQjnrP

Plain mode built the props record in the declaration order of its type,
so JsxDOM.domProps evaluated children before most attributes, while
preserve mode evaluates them last, as JSX writes them (#9104). Plain mode
now builds the same Pjsx element as preserve mode and prints it as the
call; the tag is still flattened outside preserve mode.

JS modified (plain JSX mode):
Example:
    let note = (s: string) => s->String.toUpperCase
    let element = <div title={note("t")} key={note("k")}> {React.string(note("c"))} </div>
Before (js):
    let element = JsxRuntime.jsx("div", {
      children: "c".toUpperCase(),
      title: "t".toUpperCase()
    }, "k".toUpperCase());
After (js):
    let element = JsxRuntime.jsx("div", {
      title: "t".toUpperCase(),
      children: "c".toUpperCase()
    }, "k".toUpperCase());

Review: Why keep a let-bound tag when the element has no other argument?
    Inlining a function literal into the tag drops the name the let gives
    it, which React shows; the old call always had a props argument.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Kbf3gGkPma9LAZimuQjnrP
Signed-off-by: Christoph Knittel <[email protected]>
@github-actions

Copy link
Copy Markdown

Changelog

🐛 Bug fix

  • Evaluate JSX children after the other props in plain JSX mode, as in preserve mode.

Semantic Diff

1 commit · Full page

Evaluate JSX children after the other props in both JSX modes

fea64ff · cknitt + Claude · Oct 28, 2026, 15:48 UTC

Plain mode built the props record in the declaration order of its type, so JsxDOM.domProps evaluated children before most attributes, while preserve mode evaluates them last, as JSX writes them (#9104). Plain mode now builds the same Pjsx element as preserve mode and prints it as the call; the tag is still flattened outside preserve mode.

JS modified (plain JSX mode)

let note = (s: string) => s->String.toUpperCase
let element = <div title={note("t")} key={note("k")}> {React.string(note("c"))} </div>

js

 let element = JsxRuntime.jsx("div", {
-  children: "c".toUpperCase(),
-  title: "t".toUpperCase()
+  title: "t".toUpperCase(),
+  children: "c".toUpperCase()
 }, "k".toUpperCase());

Review

  • Why keep a let-bound tag when the element has no other argument? Inlining a function literal into the tag drops the name the let gives it, which React shows; the old call always had a props argument.

@codecov

codecov Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.46%. Comparing base (85f31fb) to head (fea64ff).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #9117   +/-   ##
=======================================
  Coverage   81.46%   81.46%           
=======================================
  Files         460      460           
  Lines       64675    64678    +3     
=======================================
+ Hits        52689    52693    +4     
+ Misses      11986    11985    -1     
Files with missing lines Coverage Δ
compiler/core/j.ml 100.00% <ø> (ø)
compiler/core/js_pass_flatten_and_mark_dead.ml 78.40% <100.00%> (+0.50%) ⬆️
compiler/core/lam_pass_remove_alias.ml 85.21% <100.00%> (+0.26%) ⬆️
compiler/core/lam_util.ml 95.08% <100.00%> (ø)
compiler/ml/lambda.ml 70.30% <ø> (ø)
compiler/ml/translcore.ml 88.34% <ø> (-0.02%) ⬇️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pkg-pr-new

pkg-pr-new Bot commented Oct 28, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript@9117

@rescript/belt

npm i https://pkg.pr.new/@rescript/belt@9117

@rescript/darwin-arm64

npm i https://pkg.pr.new/@rescript/darwin-arm64@9117

@rescript/linux-arm64

npm i https://pkg.pr.new/@rescript/linux-arm64@9117

@rescript/linux-x64

npm i https://pkg.pr.new/@rescript/linux-x64@9117

@rescript/runtime

npm i https://pkg.pr.new/@rescript/runtime@9117

@rescript/win32-x64

npm i https://pkg.pr.new/@rescript/win32-x64@9117

commit: fea64ff

@github-actions

Copy link
Copy Markdown

@cknitt

cknitt commented Oct 28, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: fea64ff7af

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T16:42:59.438732Z fea64ff Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cknitt
cknitt marked this pull request as ready for review October 28, 2026 20:03
@cknitt
cknitt requested a review from cristianoc October 28, 2026 20:03
@cknitt
cknitt enabled auto-merge (squash) October 28, 2026 20:03

@cristianoc cristianoc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed the shared JSX lowering, binding preservation and evaluation-order regression tests. No blocking issues found. CI, including jsx_preserve_semantics, passes; not rerun locally.

@cknitt
cknitt merged commit b5fbe5b into master Oct 29, 2026
26 checks passed
@cknitt
cknitt deleted the fix-9104-jsx-eval-order branch October 29, 2026 01:17
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.

JSX: plain and preserve mode evaluate children and props in different orders

2 participants