Repository navigation
Fix/1422 swc jsx development - #1493
Conversation
getSwcLoaderOptions tied jsc.transform.react.development to the JSX runtime, so development builds with the default automatic runtime emitted `jsx` instead of `jsxDEV` and lost __source/__self, accurate component stacks and "open in editor", while classic production builds kept them. Config helpers don't know the mode, so RepackPlugin now sets `development` from `mode` for every builtin:swc-loader rule that doesn't set it explicitly. getSwcLoaderOptions and getJsTransformRules accept a `development` option to override it. Part of callstack#1422
Development builds now import `<importSource>/jsx-dev-runtime`; document the `development: false` override for import sources without it and that the mode-based default comes from RepackPlugin. Part of callstack#1422
🦋 Changeset detectedLatest commit: a7a6386 The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@whydidoo is attempting to deploy a commit to the Callstack Team on Vercel. A member of the Team first needs to authorize it. |
dannyhw
left a comment
There was a problem hiding this comment.
Thanks for picking this up. The bug is real, and the getSwcLoaderOptions change fixes it. I checked tester-app with its app code routed through getJsTransformRules: on main a dev bundle has 0 app fileName entries (no jsxDEV source info). With this PR it has 78. Prod has 0 in both.
My main concern is that the RepackPlugin walker (setSwcJsxDevelopment) turns out to be unnecessary. Rspack's builtin:swc-loader already fills in jsc.transform.react.development from mode when it's unset and jsc.transform exists. An explicit value is kept, because the merge only fills unset fields.
- Docs (https://rspack.rs/guide/features/builtin-swc-loader#jsctransformreact): "
jsc.transform.react.developmentis automatically set based on Rspack'smodeunless explicitly specified." - Source:
rspack_loader_swc/src/lib.rson main, also present at v1.0.0.
I checked this on Rspack 1.0.0, 1.1.0, 1.3.0, 1.6.0 and 2.2.9, leaving development unset:
- Dev:
automaticgivesjsxDEV+fileName, andclassicgives__source. - Prod: neither runtime gives either.
- An explicit
falseis kept.
I also built tester-app with only the getSwcLoaderOptions change and the walker removed. The output matches the full PR exactly: 78 in dev, 0 in prod.
So leaving the field unset in the helper is the whole fix. Inline suggestions:
- Drop
setSwcJsxDevelopmentand theRepackPluginhook. Sorry, I know its unit tests were only just added at review request. - Update the docs, JSDoc and changeset to say Rspack's
builtin:swc-loadersets the default, notRepackPlugin. - Make the integration tests check the compiled output instead of
compiler.options.
Keeping the new development override option makes sense. Patch changeset is fine. If you'd rather keep the walker as insurance for older Rspack 1.x (the 1.x docs don't mention this behaviour, though the 1.0.0 source has it), I wouldn't block on that. In that case, though, the docs should still say that Rspack does this by default.
…ode and remove deprecated utility
dannyhw
left a comment
There was a problem hiding this comment.
Thanks for the quick turnaround, this looks great. I re-checked a7a63865 locally:
- The new
swc-jsx-developmentintegration tests pass (6/6 on Rspack). - With
main'sjsxRuntime === 'classic'logic temporarily restored, exactly the two buggy cases fail (automatic in dev, classic in prod), so the tests catch the regression. - The full integration suite and the repack unit tests pass, and typecheck is clean.
Part of #1422.
Summary
getSwcLoaderOptions(used bygetJsTransformRules) setjsc.transform.react.developmentfrom the JSX runtime instead of the build mode. As a result:automaticruntime emittedjsxinstead ofjsxDEV, so they had no__source/__self, accurate component stacks or "open in editor";classicproduction builds kept the dev transforms.developmentoption ongetSwcLoaderOptionsandgetJsTransformRules({ swc: { development } }).<importSource>/jsx-dev-runtime. If a customimportSourcedoesn't ship it, setswc: { development: false }.Test plan
tests/integration/src/plugins/RepackPlugin.test.ts(Rspack): withgetJsTransformRules()+RepackPlugin, development mode givestrue, production givesfalse, and an explicitdevelopment: falseis kept. These were red before the change.