Repository navigation
Conversation
A --jsx-* flag names a factory, a fragment, an import source or a runtime. Since 1.4.0 it also selected the production runtime in `bun build`, where 1.3.14 and the same build without the flag use the development runtime. In `bun build` a flag now writes `development: None`, and keeps what a bunfig.toml said. NODE_ENV, --production, the bunfig.toml and the tsconfig.json of the working directory then choose. JSX in a macro that the build runs follows the bundle. Outside `bun build` a flag still writes `Some(false)`.
|
Updated 10:25 PM PT - Nov 9th, 2026
✅ @robobun, your commit 14c37b36a4329f50cb784cabe52466340b0d3f5f passed in 🧪 To try this PR locally: bunx bun-pr 48337That installs a local version of the PR into your bun-48337 --bun |
|
Status: ready for review at 14c37b3. That commit merges the base (#48152 at 994f466), which added 16 test cases. The code of this PR is the same as at 8d9ddef. It is stacked on #48152, and it waits for a maintainer's choice between this change and a docs line (see "The decision" in the description). How I reproduced it, with echo "console.log(<a b='1'>x</a>, <>y</>);" > j.jsx
bun build --external='*' --jsx-import-source=zzsrc j.jsx
# 1.3.14: import { jsxDEV, Fragment } from "zzsrc/jsx-dev-runtime"
# 1.4.0 to main, and #48152: import { jsx, Fragment } from "zzsrc/jsx-runtime"
# this branch: import { jsxDEV, Fragment } from "zzsrc/jsx-dev-runtime"
Test: CI on 14c37b3 (build 139566): 184 jobs passed and none failed. 4 |
There was a problem hiding this comment.
Findings marked 🟡 are optional suggestions and need no follow-up push.
Additional findings (outside the current diff — GitHub can't attach inline comments there):
-
🟡
src/runtime/cli/Arguments.rs— Users ofbun compile --aot --jsx-import-source=xwith noNODE_ENV, no--productionand no cwd tsconfig"react-jsx"now get an executable whose JSX callsjsxDEV, and the change ships no test for that entry point.is_buildat src/runtime/cli/Arguments.rs:1178 coversCommandTag::CompileCommand, and the AOT route at src/runtime/cli/compile_command/configuration.rs:447 only forcesdevelopment = falseforproduction; the dismissal traced only--library, which routes to build_command.rs. Fix: pinbun compile(with and without--aot) in the matrix alongsidebun build --compile, and confirm the AOT snapshot at bundler/aot/options.rs:243 sees the same resolved value as the bundle. [also at: test/bundler/transpiler/jsx-tsconfig-react-jsx.test.ts:257 - nit: thebun compileentry point also changes behaviour here but no test exercises it. Theis_buildgate at src/runtime/cli/Arguments.rs:1178 coversCommandTag::CompileCommand, andbun compileaccepts every--jsx-*flag via TRANSPILER_PARAMS_ (src/runtime/cli/Arguments.rs:908), sobun compile --jsx-import-source=x main.jsxmoves fromx/jsx-runtimetox/jsx-dev-runtimetoo.]Why this was flagged
Trigger:
bun compile --aot --jsx-import-source=x main.jsx(andbun compilewhen--aotis implied), enteringparse()withcmd == CommandTag::CompileCommand, sois_buildat src/runtime/cli/Arguments.rs:1178 is true and :2007 writesdevelopment: None.CompileCommand::exec_commandat src/runtime/cli/compile_command/command.rs:31-41 sends an AOT build torun()andconfiguration::configure, not toBuildCommand::exec; there src/runtime/cli/compile_command/configuration.rs:447 forcesfalseonly underctx.bundler_options.production, and :433 callsconfigure_linker()which at src/bundler/transpiler.rs:575 fills from the cwd tsconfig only. The AOT options snapshot at src/bundler/aot/options.rs:243 then freezesforced_jsx_development()into the sema config. On the base the flag carriedSome(false)into this path, so the executable calledjsx; now it callsjsxDEV, and an import source that ships only./jsx-runtimefails the compile withCould not resolve: "x/jsx-dev-runtime". Remedy: addbun compilerows and verify the AOT path against the bundle path.Verification: src/runtime/cli/Arguments.rs:1178
let is_build = matches!(cmd, CommandTag::BuildCommand | CommandTag::CompileCommand);so :2007 writesNone. src/runtime/cli/compile_command/configuration.rs:447-450 only forcesdevelopment = falseunderctx.bundler_options.production, so the base'sSome(false)becomes dev forbun compile. test/aot/build-flags.test.ts:312 spawns only[bunExe(), "build", "--compile", ...].
| // Outside `bun build`, a `--jsx-*` flag selects the production runtime, as it has since 1.2.3. | ||
| let development = |of_bunfig: Option<bool>| if is_build { of_bunfig } else { Some(false) }; |
There was a problem hiding this comment.
🔴 Existing bun build --jsx-* users get a different runtime after merging: with no NODE_ENV, --production or tsconfig "react-jsx", JSX now imports <source>/jsx-dev-runtime instead of jsx-runtime. The development closure at Arguments.rs:1996 returns None for BuildCommand/CompileCommand where the base wrote Some(false). This follows from the stated purpose, but it is a silent default flip for a shipped CLI flag: a source with only ./jsx-runtime now fails with Could not resolve: "x/jsx-dev-runtime". Fix: either keep production as the fallback when nothing else chose, or land the flip only with a breaking-change note and an update to the --jsx-* flag docs, which this PR does not touch.
Why this was flagged
A user runs bun build --jsx-import-source=x main.jsx (also with --compile or --no-bundle) with NODE_ENV unset, no --production, and no tsconfig.json "jsx": "react-jsx" in the working directory. On the base branch src/runtime/cli/Arguments.rs:2007 and :2023 wrote development: Some(false), so the bundle imported x/jsx-runtime and called jsx. After the change the closure at src/runtime/cli/Arguments.rs:1996 returns None (or the bunfig value) because is_build (Arguments.rs:1178) is true, so the bundler falls through to the dev runtime and imports x/jsx-dev-runtime with jsxDEV calls. If x exposes only ./jsx-runtime the build now exits 1 with Could not resolve: "x/jsx-dev-runtime"; if the output has React external and is run under NODE_ENV=production it throws TypeError: jsxDEV is not a function where the base build ran. test/bundler/transpiler/jsx-tsconfig-react-jsx.test.ts:258-264 pins the new dev result for every --jsx-* flag. No docs file is updated and there is no deprecation or note path in the code, so nothing warns the affected users.
Verification: src/runtime/cli/Arguments.rs:1178 is_build = matches!(cmd, BuildCommand | CompileCommand); :1996 let development = |of_bunfig| if is_build { of_bunfig } else { Some(false) }; used at :2007 development(None) and :2023 development(prev.development) where the base wrote Some(false). Pragma::default() development: true (jsx.rs:187), so None yields the dev runtime.
An automated safety screen replaced some characters, such as angle brackets, in the code quoted in this comment with HTML escape codes.
There was a problem hiding this comment.
This result is the purpose of the PR, and a maintainer has to choose it. The description puts it as one decision with two outcomes: this change, or one docs line that says a --jsx-* flag means production. Rows 1c and 1d of its table are the two failures that you name.
On the docs: docs/bundler/esbuild.mdx:71 already states the rule that this PR gives a flagged build ("If compilerOptions.jsx is "react-jsx", or if NODE_ENV=production, Bun uses the jsx transform. Otherwise, it uses jsxDEV"). No page says that a flag selects the production runtime: docs/snippets/cli/run.mdx:239-253 only says what each flag names. So this PR has no docs text to change. The other outcome is the one that needs a new line. Whether the change goes on a list of breaking changes is part of the same decision.
I leave this thread open for that decision.
|
On the finding about
The three commands agree on each build, so the compiled code gets the value that a bundle gets. Row 1 of the description now names |
…obobun/49c51871/bun-build-jsx-flags-leave-dev-prod-unset # Conflicts: # test/bundler/transpiler/jsx-tsconfig-react-jsx.test.ts
There was a problem hiding this comment.
Code review found no new issues
No new issues were found in this update; 1 finding from earlier reviews is still open above.
Still open from earlier reviews (1):
- 🔴
src/runtime/cli/Arguments.rs:1996—Existing bun build --jsx-* users get a different runtime after merging: with no NODE_ENV, --production or tsconfig "rea…
If you have decided not to act on one of these findings, resolve its thread (a reply alone leaves it open) and the next review stops counting it. To review this commit again now, use Re-run on its "Claude Code Review" check.
Stacked on #48152: merge that one first.
Problem
NODE_ENVunset,bun build --jsx-import-source=ximportsx/jsx-runtime. Without the flag, and on 1.3.14:x/jsx-dev-runtime.--jsx-runtime,--jsx-factoryand--jsx-fragmentdo the same.src/runtime/cli/Arguments.rs:2005and:2021writedevelopment: falsefor each of the four. Since 1.4.0 (jsx: honor tsconfig "react-jsx" vs "react-jsxdev" for the automatic runtime #34422),bun buildno longer overwrites that value.Fix
bun build, each of the four writesNoneand keeps what a bunfig.toml said.NODE_ENV,--production, bunfig.toml and the tsconfig.json of the working directory then choose.bun builda flag still writesSome(false).bun <file>,bun runandbun testdo not change.test/bundler/transpiler/jsx-tsconfig-react-jsx.test.ts(20 new cases, 11 fail on the base branch),test/aot/build-flags.test.ts.Background
jsxDEVfrom<source>/jsx-dev-runtime(development) orjsxfrom<source>/jsx-runtime(production).Bun.build()and for a bunfig.toml withoutjsx#48152 makesapi::Jsx.developmentanOption<bool>.Nonetakes"react-jsx"or"react-jsxdev"from the tsconfig.json, unlessNODE_ENVchose.--jsx-*flag means production. It keeps 1.4.x as it is.Downsides
./jsx-runtime:Could not resolve: "x/jsx-dev-runtime".NODE_ENV=production,--productionor tsconfig"react-jsx"keeps it on production.bun buildbeside a tsconfig.json runs 7 more instructions, once.Notes
The decision
1.4.0 made two changes at the same time. Tsconfig
"react-jsx"began to select the production runtime (#34422), andbun buildstopped writing its own choice over thedevelopment: falsethat a flag had always carried. The second one was not announced: the list of breaking changes of 1.4 (#28792) has only the first. On the run path the same literal selectsjsx-runtimesince 1.2.3 (#17013), and this PR does not touch it.So the question is what a
--jsx-*flag means inbun build:Bun.build({ jsx: { importSource } })after Leave JSX dev/prod unset forBun.build()and for a bunfig.toml withoutjsx#48152.docs/bundler/esbuild.mdx.Commands that behave differently now
NODE_ENVandBUN_ENVare not set unless the row says so. "dev" isjsx-dev-runtime, "prod" isjsx-runtime. "Base" is #48152.--jsx-*stands for--jsx-runtime,--jsx-import-source,--jsx-factoryor--jsx-fragment.bun build --jsx-*, also--no-bundle,--compile,--compile --aotandbun compile(its short form). JSX in a macro that the build runs follows the bundleNODE_ENV=test(a value other thanproductionanddevelopment), or with--env=disable./jsx-runtimeCould not resolve: "x/jsx-dev-runtime"(a macro:Cannot find module 'x/jsx-dev-runtime')NODE_ENV=productionTypeError: jsxDEV is not a functionTypeError: jsxDEV is not a function, as the same build without the flagbun build --jsx-*beside bunfigjsx = "react-jsxDEV"bun build --jsx-*when the tsconfig.json with"react-jsx"is not in the working directory: in a subdirectory, in a parent, or nested under a root tsconfig.json that says"react-jsxdev"What stays:
bun build --jsx-*beside tsconfig"react-jsx"in the working directory is prod. In a bundle,NODE_ENV=productionor--productionis prod, also beside tsconfig"react-jsxdev". WithNODE_ENV=developmentit is dev.Counts, base against this PR, one process per result: of 80
bun buildresults (5 tsconfig.json states, 4NODE_ENVstates, bundle and--no-bundle, with and without--jsx-import-source), 14 move, all with the flag and all from prod to dev. 0 of 960Bun.build()results and 0 of 40bun <file>results move. The 28 rows of the report that started this: 7 change (02 to 06, 14, 19), all to dev. Rows 13 and 28 stay prod.Not changed by this PR
jsx-runtimeforbun <file>,bun run,-e, a Worker,bun test,BUN_OPTIONSand--compile-exec-argv. An earlier revision moved them too. An import source with only./jsx-runtimethen exits 1 withCannot find module 'x/jsx-dev-runtime', so they stay. With a yes for the run path, theis_buildtest atsrc/runtime/cli/Arguments.rs:1996goes away.bun test --parallelloadjsx-runtimewhile the serial run loadsjsx-dev-runtime:src/runtime/cli/test/parallel/runner.rs:480gives each worker a--jsx-runtimeflag that nobody typed. 1.4.4 and main do the same. I reported it for a separate fix.--no-bundletakes the value of each file from its tsconfig.json. There a tsconfig.json that says"react-jsxdev"goes beforeNODE_ENV=productionand--production, with and without a flag, as on main. bun build --no-bundle: apply force_node_env to the per-file JSX pragma #38070 is open for that path.NODE_ENV=production bun buildwith no flag beside a tsconfig.json that does not say"react-jsx"emitsjsxDEV(bun build: keep NODE_ENV=production when tsconfig.json does not set "jsx" #38050). With a flag it is prod.--jsx-side-effectswith none of the four. It has no effect on 1.4.4 and on main, so such a build is a build with no flag. CLI: fixes for bun run, flags, bunfig.toml, .env, --filter, bun init and completions #46007 makes it work alone.Other PRs
NODE_ENVguard and without the limit tobun build. Without the guard,NODE_ENV=production bun build --jsx-*beside tsconfig"react-jsxdev"goes from prod to dev. It can be closed when Leave JSX dev/prod unset forBun.build()and for a bunfig.toml withoutjsx#48152, this PR and CLI: fixes for bun run, flags, bunfig.toml, .env, --filter, bun init and completions #46007 cover it.Measurements
Release builds of the base (1cdba61) and of this branch. The counts are from
gdb,llvm-nmandllvm-size.arguments::parse, 3 bytes smaller..textis 108,256,297 bytes in both.configure_linker_with_auto_jsxruns itself forbun build --jsx-import-source: 41 to 41 with no tsconfig.json, 64 to 71 beside tsconfig"react-jsx". Forbun --jsx-import-source <file>: 64 to 64.Tests
jsx-tsconfig-react-jsx.test.ts: 99 pass on the debug build (83 before the base added 16 cases). 18 rows arebun buildwith a flag, and 2 rows run a macro. On the base branch 11 of them fail. The others pin what stays.test/aot/build-flags.test.ts: 12 pass. Themineshim tellsjsxfromjsxDEV. The--jsx-import-sourcecase is built with--compileand with--compile --aotbeside--define process.env.NODE_ENV="staging", and prints the development form (row 1b). On the base branch that case fails. A new case pins tsconfig"react-jsx"with a flag as prod for both executables.Review
Self-reviewed together with #48152: 32 concerns raised for the whole change. For this part the review asked for a PR of its own, because it is the part with a design question, and for rows 1c and 1d to be stated. Both are done. Nothing was rejected.
no test proof · iteration 4 · platform-specific test(s) that do not run on this machine, deferring to CI, which covers all platforms: test/aot/build-flags.test.ts