fix(react): respect tsconfig jsxImportSource (fix #1448) - #1450
Open
cpruijsen wants to merge 1 commit into
Open
Conversation
The native compiler lowered JSX before Vite could apply per-file tsconfig inference. Use the same tsconfig resolver as Vite's oxc transform so compiler: true preserves jsxImportSource.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #1448.
react({ compiler: true })lowers JSX invite:react-compilerwithoxc-transform-react. That transform defaultsjsx.importSourceto"react"when the option is unset. Vite's oxc transform never sees the original JSX, so the per-file tsconfig inference restored in #726 does not apply.With no plugin-level
jsxImportSource, the compiler transform now readscompilerOptions.jsxImportSourcefrom the file's tsconfig using the sameresolveTsconfigVite uses for oxc JSX. An explicitjsxImportSourceoption still overrides every file.Reproduction from the issue (two TSX files, no pragmas):
jsxImportSource: "@emotion/react"{ compiler: false }@emotion/react/jsx-runtimereact/jsx-runtime{ compiler: true }(before)react/jsx-runtimereact/jsx-runtime{ compiler: true }(after)@emotion/react/jsx-runtimereact/jsx-runtime{ compiler: true, jsxImportSource: "@emotion/react" }@emotion/react/jsx-runtime@emotion/react/jsx-runtimeWhat I chose: fill
jsx.importSourcefrom the file's tsconfig inside the compiler plugin.Alternative: set
jsx: "preserve"in the compiler plugin so Vite's oxc transform keeps owning JSX, Fast Refresh, and tsconfig inference.Why: #1419 put JSX and Fast Refresh in the compiler plugin so the compiler sees the original AST. This change only supplies the missing import source and stays reversible. Happy to switch to preserve-JSX if that is preferred.
resolveTsconfigis a hidden rolldown export currently used by Vite. It is loaded through Vite's installation so this package does not gain a new runtime dependency. If you would rather have a public Vite helper, this call site is the consumer.Checklist
jsxImportSourceis inferred from tsconfig; no extra docs.packages/plugin-reactunit tests).