Babel plugins that read AST `loc` produce wrong positions when running after OXC
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 45/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 静か
- 技術スタック
- babel, react, typescript
- 領域
- build-system, frontend
調査の方向性
リンクされている vite-babel-order-repro から始め、@vitejs/plugin-react の OXC transform と @rolldown/plugin-babel の post-processing path を追跡します。pre と post の ordering における Babel AST の loc 値と OXC の jsxDEV source information を比較します。カスタム Babel plugins が元のソース位置を受け取り、OXC の位置がずれなければ完了です。
索引モデルが issue の本文から書いたものです。
説明
Related plugins
Describe the bug
When a Babel plugin runs after @vitejs/plugin-react's OXC transform (using @rolldown/plugin-babel with enforce: 'post' or a custom plugin), the Babel AST loc values refer to the OXC-transformed code, not the original source. Any Babel plugin that reads loc.start.line / loc.start.column to embed source positions in the output will produce incorrect values.
This was not an issue with @vitejs/plugin-react v5 where Babel handled both JSX transform and custom plugins in a single pass — loc always pointed to the original source.
Example
We have a Babel plugin that inserts ComponentName.__debugSourceDefine = { fileName, lineNumber, columnNumber } after each React function component, using the function body's loc:
FunctionDeclaration(path, state) {
const name = path.node.id.name;
const loc = path.node.body.loc; // ← wrong after OXC transform
// inserts: Foo.__debugSourceDefine = { fileName: "...", lineNumber: loc.start.line, ... }
path.insertAfter(createDebugInfo(name, state.file.opts.filename, loc));
}
With v5 (react({ babel: { plugins: [myPlugin] } })), loc.start.line referred to the original .tsx file. With v6, OXC transforms JSX first, changing line numbers. Babel sees the transformed code and its loc values are offset.
The dilemma — no configuration produces correct results
With enforce: 'pre' (default) — Babel runs before OXC:
- ✅
__debugSourceDefineline numbers are correct (Babel sees original source) - ❌ OXC's
jsxDEV()source info is wrong — every JSX element in the app gets shifted line numbers because Babel inserted__debugSourceDefineblocks (4+ lines each) before OXC processed the file
With enforce: 'post' — Babel runs after OXC:
- ❌
__debugSourceDefineline numbers are wrong (Babel ASTlocrefers to OXC-transformed code, not the original source) - ✅ OXC's
jsxDEV()source info is correct (OXC saw the original source)
Reproduction
https://github.com/Artur-/vite-babel-order-repro
Steps to reproduce
npm install
npx vite
Open in browser — the page automatically verifies source positions.
System Info
System:
OS: macOS 26.3.1
CPU: (10) arm64 Apple M1 Max
Binaries:
Node: 24.14.0
npm: 11.9.0
Used Package Manager
npm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
- 主要言語
- TypeScript
- スター
- 1.2k
- フォーク
- 287
- 平均マージ
- 1日 17時間
- マージ済み PR(30日)
- 19
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 日以内に返信
-
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 日以内に返信
-
[plugin-rsc] inline "use server" function declarations lose hoisting and throw TDZ ReferenceError対応中かも @draarivpatel-ui が 2 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
vitejs/vite-plugin-react#1566 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
vitejs/vite-plugin-react の issue をすべて見る
似ている issue
-
good first issue help wanted
難易度 2/5 1時間未満 初心者へのやさしさ 86/100
Intelligenza-Umana/intelligenza-umana-web#16 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
open-webui/open-webui#35184 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
danielmiessler/LifeOS#3001 ·
メンテナーはふだん 5 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 1 日以内に返信