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.
|
The initial per-file jsxImportSource case works, but the new TsconfigCache becomes stale in a running dev server.
With compiler: false, the same test correctly switches A → B → React. Adding only tsconfigCache?.clear() before the new resolveTsconfig call also makes the native-compiler test pass. This isolates the problem to the cache introduced here, rather than stale HTTP/module responses. |
The TsconfigCache added in this PR is created once per plugin instance and never invalidated, so editing a tsconfig during dev keeps resolving the old jsxImportSource: Vite sends a full-reload, but later responses still import the previous source. Reported by @doctor8296 on Vite 8.2.2 / Rolldown 1.2.6. Clearing the cache before every resolveTsconfig call fixes the staleness but leaves the cache doing nothing. The cache parameter is optional and upstream resolves without one, so this removes it instead. Adds a regression test that reuses a single plugin instance across a tsconfig change. It fails with the cache present, resolving @emotion/react where react is expected.
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).