nextjs - 💡(How to fix) Fix Duplicate SWC transform for `use client` components when React Compiler is disabled [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#90245Fetched 2026-04-08 00:20:31
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Author
Timeline (top)
labeled ×2closed ×1commented ×1issue_type_added ×1

When using Next.js 16 with SWC and React Compiler disabled, use client components appear to be transformed twice by SWC.

The duplicate transformation produces identical AST output.

This behavior can be observed using a custom SWC plugin that writes intermediate stage output to disk.


Root Cause

In projects with many use client components:

  • SWC plugin execution cost doubles
  • Instrumentation cost doubles
  • Build time and memory may increase

For tooling that relies on SWC transforms (e.g., instrumentation plugins), this introduces measurable overhead.


Code Example

.swc-plugin-stage-output

---

.swc-plugin-stage-output/

---

pnpm build

---

.swc-plugin-stage-output/

---

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.0.0: Wed Sep 17 21:41:45 PDT 2025; root:xnu-12377.1.9~141/RELEASE_ARM64_T6000
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 25.2.1
  npm: 11.6.2
  Yarn: N/A
  pnpm: 10.13.0
Relevant Packages:
  next: 16.1.6 // Latest available version is detected (16.1.6).
  eslint-config-next: N/A
  react: 19.2.3
  react-dom: 19.2.3
  typescript: 5.9.3
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/canyon-project/nextjs16-swc-duplicate-compilation

To Reproduce

Description

When using Next.js 16 with SWC and React Compiler disabled, use client components appear to be transformed twice by SWC.

The duplicate transformation produces identical AST output.

This behavior can be observed using a custom SWC plugin that writes intermediate stage output to disk.


Reproduction Repository

https://github.com/canyon-project/nextjs16-swc-duplicate-compilation.git


How to Observe

The reproduction includes a custom SWC plugin:

.swc-plugin-stage-output

This plugin writes SWC stage outputs to:

.swc-plugin-stage-output/

After running build:

pnpm build

Please inspect:

.swc-plugin-stage-output/

You will see:

  • The same source file being transformed twice
  • The generated AST output is identical
  • The transform stage identifiers indicate two independent passes

Observed Behavior

  • Only happens when:

    • Component contains "use client"
    • React Compiler is disabled
  • Does NOT happen when React Compiler is enabled

  • Both compilation passes produce identical AST output

  • SWC plugin hooks are executed twice for the same file


Questions

  1. Is this double transform expected?
  2. Is this related to separate client/server graph compilation?
  3. If intentional, is identical AST transformation unavoidable?
  4. Could this be optimized to avoid redundant identical passes?

Why This Matters

In projects with many use client components:

  • SWC plugin execution cost doubles
  • Instrumentation cost doubles
  • Build time and memory may increase

For tooling that relies on SWC transforms (e.g., instrumentation plugins), this introduces measurable overhead.


Technical Hypothesis (Optional)

It appears that:

  • Next.js builds separate client and server graphs
  • use client modules are processed independently in both graphs
  • However, in the no-React-Compiler case, both passes generate identical AST

If this duplication is purely architectural (graph separation), perhaps memoization or transform result reuse could reduce redundant work.

Current vs. Expected behavior

Observed Behavior

  • Only happens when:

    • Component contains "use client"
    • React Compiler is disabled
  • Does NOT happen when React Compiler is enabled

  • Both compilation passes produce identical AST output

  • SWC plugin hooks are executed twice for the same file

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.0.0: Wed Sep 17 21:41:45 PDT 2025; root:xnu-12377.1.9~141/RELEASE_ARM64_T6000
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 25.2.1
  npm: 11.6.2
  Yarn: N/A
  pnpm: 10.13.0
Relevant Packages:
  next: 16.1.6 // Latest available version is detected (16.1.6).
  eslint-config-next: N/A
  react: 19.2.3
  react-dom: 19.2.3
  typescript: 5.9.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

SWC

Which stage(s) are affected? (Select all that apply)

next build (local)

Additional context

No response

extent analysis

Fix Plan

Disable Duplicate Compilation

To fix the issue of duplicate compilation of use client components when React Compiler is disabled, we can modify the next.config.js file to disable duplicate compilation.

Step 1: Update next.config.js

module.exports = {
  // ... other configurations ...
  experimental: {
    duplicateCompilation: false,
  },
};

Step 2: Update swc.config.js (if applicable)

If you have a custom swc.config.js file, you can also add the following configuration to disable duplicate compilation:

module.exports = {
  // ... other configurations ...
  experimental: {
    duplicateCompilation: false,
  },
};

Verify Fix

  1. Run pnpm build to rebuild the project.
  2. Inspect the .swc-plugin-stage-output directory to ensure that the use client components are only transformed once.
  3. Verify that the build time and memory usage have not increased.

Extra Tips

  • Make sure to test the fix in a production-like environment to ensure that it does not introduce any regressions.
  • If you are using a custom SWC plugin, ensure that it is compatible with the updated configuration.
  • Consider enabling the React Compiler to avoid duplicate compilation altogether.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

nextjs - 💡(How to fix) Fix Duplicate SWC transform for `use client` components when React Compiler is disabled [1 comments, 2 participants]