AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Turbopack Runs SwcPlugins After React Compiler, Breaking Lingui Macro Message Extraction

When reactCompiler and turbopackRustReactCompiler are enabled, the Rust React Compiler runs in the preprocess stage before user-registered swcPlugins, so macro plugins like @lingui/swc-plugin see compiler-hoisted JSX and emit incorrect message IDs, causing silent translation fallback and client/server mismatch.

highConfidence 90%Next.jsAffected V16.4.0-Canary.57Affected V16.3.6

Origin Analysis

In turbopack/crates/turbopack/src/module_options/mod.rs, ReactCompilerRust is appended to ecma_preprocess while swcPlugins are registered at EcmascriptTransformStage::Main, so the compiler always transforms JSX before user plugins run; macros that need original source text (e.g., Lingui Trans) receive hoisted temporaries like {t2} and compute wrong IDs.
1. Clone https://github.com/kristoferma/turbopack-swc-plugin-order-repro. 2. npm install. 3. REACT_COMPILER=0 npx next build and grep for message:. 4. rm -rf .next && REACT_COMPILER=1 npx next build and grep again. Observe with compiler on, static JSX child becomes {t2} placeholder and extracted message differs from lingui extract catalog, causing silent fallback.

Fixing Code Block

Edge Case Audit

Opt-in reorders all swcPlugins before React Compiler; plugins that relied on post-compiler AST may break. Not yet available in stable and may change. Ensure the plugin is removed from Main stage to avoid double execution. Test client and SSR output for consistency; rollback by setting the flag to false (or removing it). Does not address customMacros; users with Lingui may still need to configure React Compiler skip rules if customMacros is eventually exposed.

Ecosystem Topology