Skip to content

Duplicate SWC transform for use client components when React Compiler is disabled #90248

@travzhang

Description

@travzhang

Link to the code that reproduces this issue

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

To Reproduce

  1. pnpm i
  2. npm run build
  3. look .swc-plugin-stage-output

Current vs. Expected behavior

After testing the Next.js + Turbopack combination, we observed duplicate identical filenames appearing in the SWC AST during compilation. Our investigation identified that this behavior is inherent to Next.js' compilation workflow.
To address this ambiguity (consistent with Vite's pattern), we propose appending a layer query parameter to the filename passed to SWC (via TransformContext) — e.g., app/page.tsx?layer=app-rsc — to enable SWC plugins to distinguish between these duplicate entries.
For extensibility (aligned with next-swc-loader), we use a named parameter format:

  • Use ?layer=value for paths with no existing query string
  • Use &layer=... for paths that already contain a query string
Image Image

Expected behavior

Image

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    SWCRelated to minification/transpilation in Next.js.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions