react({ compiler: true }) ignores tsconfig jsxImportSource
维护者通常 1 天内回复
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 74/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- react, typescript, vite
调研方向
从 repro.mjs 中自包含的复现,以及 styled/tsconfig.json 和 plain/tsconfig.json fixture 开始;运行 npm ci --ignore-scripts 和 npm run repro。追踪 jsx.importSource 从 reactOptions.jsxImportSource 提供时的原生编译器转换。完成标准是:启用编译器的输出对 styled/component.tsx 保留 @emotion/react/jsx-runtime,对 plain/component.tsx 保留 react/jsx-runtime,同时显式的全局 override 仍按所示方式运行。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
Enabling the native React Compiler with react({ compiler: true }) changes the JSX runtime selected from each file's nearest tsconfig.json. With no explicit plugin-level jsxImportSource, a file configured to use @emotion/react instead imports react/jsx-runtime.
Expected: enabling the compiler should preserve the documented per-file tsconfig inference.
Two identical TSX files produce these imports:
| Plugin options | styled/component.tsx (jsxImportSource: "@emotion/react") |
plain/component.tsx (default React) |
|---|---|---|
{ compiler: false } |
@emotion/react/jsx-runtime |
react/jsx-runtime |
{ compiler: true } |
react/jsx-runtime — incorrect |
react/jsx-runtime |
{ compiler: true, jsxImportSource: "@emotion/react" } |
@emotion/react/jsx-runtime |
@emotion/react/jsx-runtime |
The last row is expected global-override behavior, not another bug: setting one global source cannot preserve both per-file configurations.
Reproduction
Self-contained files below. No pragmas, Babel, CSS plugins, or workspace tooling are involved. Runtime imports are externalized so the test can inspect the emitted specifiers without installing or executing React/Emotion.
Create the files in an empty directory, then run:
npm install --ignore-scripts
npm run repro
The script checks the compiler-disabled baseline, prints all three configurations, and exits with code 1 for the compiler-enabled regression. The final global-override demonstration does not affect the exit code.
Complete reproduction files
package.json
{
"name": "vite-jsx-import-source-repro",
"private": true,
"type": "module",
"scripts": {
"repro": "node repro.mjs"
},
"devDependencies": {
"@vitejs/plugin-react": "6.1.1",
"oxc-transform-react": "0.145.0",
"vite": "8.2.2"
}
}
styled/tsconfig.json
{
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "@emotion/react"
}
}
plain/tsconfig.json
{
"compilerOptions": {
"jsx": "react-jsx"
}
}
Both styled/component.tsx and plain/component.tsx:
export function Component() {
return <div>Hello</div>;
}
repro.mjs
import assert from "node:assert/strict";
import { fileURLToPath } from "node:url";
import react from "@vitejs/plugin-react";
import { build } from "vite";
const root = fileURLToPath(new URL(".", import.meta.url));
const expected = {
styled: "@emotion/react/jsx-runtime",
plain: "react/jsx-runtime",
};
let failures = 0;
for (const options of [
{ compiler: false },
{ compiler: true },
{ compiler: true, jsxImportSource: "@emotion/react" },
]) {
const buildOutput = await build({
root,
configFile: false,
logLevel: "silent",
plugins: [react(options)],
build: {
write: false,
minify: false,
lib: {
entry: {
styled: `${root}styled/component.tsx`,
plain: `${root}plain/component.tsx`,
},
formats: ["es"],
},
rolldownOptions: {
external: /^(react|@emotion\/react)(\/|$)/,
output: { preserveModules: true },
},
},
});
console.log(JSON.stringify(options));
const chunks = [buildOutput].flat().flatMap((output) => output.output);
for (const [entry, runtime] of Object.entries(expected)) {
const chunk = chunks.find(
(output) =>
output.type === "chunk" &&
output.facadeModuleId === `${root}${entry}/component.tsx`,
);
assert.ok(chunk, `Missing entry: ${entry}`);
const imports = chunk.imports.filter((specifier) =>
specifier.endsWith("/jsx-runtime"),
);
const matches = imports.length === 1 && imports[0] === runtime;
console.log(
` ${entry}: ${imports.join(", ")} (${matches ? "PASS" : "FAIL"})`,
);
if (!options.compiler) assert.deepEqual(imports, [runtime]);
if (!matches && !options.jsxImportSource) failures++;
}
}
process.exitCode = failures ? 1 : 0;
System Info
macOS 26.4.1 arm64
Node 22.14.0
npm 10.9.2
vite 8.2.2
@vitejs/plugin-react 6.1.1
oxc-transform-react 0.145.0
Also reproduced after a clean npm ci --ignore-scripts using the generated lockfile.
Related context
- #726 restored tsconfig inference in the regular JSX transform path. It predates the native compiler integration from #1419 and does not cover this compiler-enabled path.
- #1224 concerns file-level JSX pragma comments being moved below imports. This reproduction contains no pragmas, so moving comments cannot address this case.
- In the native compiler transform,
jsx.importSourceis supplied fromreactOptions.jsxImportSource, and JSX is already lowered before Vite's regular transform can apply the file's tsconfig.
- 主要语言
- TypeScript
- 星标
- 1.2k
- 派生
- 287
- 平均合并
- 1 天 19 小时
- 30 天内合并 PR
- 21
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
vitejs/vite-plugin-react 的其他 Issue
-
plugin-rsc: a client reference's CSS is linked before the CSS of the chunks it imports (build)可能已有人在做 @wozhenbang2004 于 7 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 84/100
vitejs/vite-plugin-react#1570 ·
维护者通常 1 天内回复
-
[plugin-rsc] With two dev servers in one process, loadModule runs in the last server's environment未关闭
难度 4/5 3-5 天 新手友好度 57/100
vitejs/vite-plugin-react#1589 ·
维护者通常 1 天内回复
-
pending triage
难度 4/5 3-5 天 新手友好度 35/100
vitejs/vite-plugin-react#1581 ·
维护者通常 1 天内回复
-
[plugin-rsc] Build exits 0, but the app fails at runtime: a server action imported only by browser code is missing from the RSC build可能已有人在做 @NeilPant 于 4 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 48/100
vitejs/vite-plugin-react#1578 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 42/100
vitejs/vite-plugin-react#1577 ·
维护者通常 1 天内回复
查看 vitejs/vite-plugin-react 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
ardia-browser/ardia#4778 ·
维护者通常 1 天内回复
-
[M09] Silence parser misreads ffmpeg times in scientific notation (6.25e-05 → 6.25 s)可能已有人在做 @G-darshan-32 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 78/100
clipy-recorder/clipy#164 · 1 条评论 ·
-
bug from-app needs-triage
难度 2/5 1-3 小时 新手友好度 72/100
nightly-labs/openbot#18462 ·
维护者通常 1 天内回复
-
Fast and light shell approval "Always allow" button shows raw English backticks and scrambles commands in Arabic可能已有人在做 @tylerbea 今天认领。 未关闭agent-ui bug p3
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
[Bug] Windows: Ctrl+C / Ctrl+V not working in chat input box可能已有人在做 @PranavTJ-05 今天认领。 未关闭comp/desktop desktop/chat desktop/shell os/windows P2 type/bug
难度 2/5 1-3 小时 新手友好度 76/100
NousResearch/hermes-agent#161023 · 2 条评论 ·
维护者通常 1 天内回复