Duplicate SWC transform for use client components when React Compiler is disabled
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 142k
- Forks
- 32.4k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 351
Description
Link to the code that reproduces this issue
https://github.com/canyon-project/nextjs16-swc-duplicate-compilation
To Reproduce
- pnpm i
- npm run build
- 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=valuefor paths with no existing query string - Use
&layer=...for paths that already contain a query string
Expected behavior
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked reproduction: run pnpm i and npm run build, then inspect .swc-plugin-stage-output to confirm the duplicate entries. Trace the filename passed to SWC through TransformContext and next-swc-loader, including existing query strings. Done means duplicate transforms can be distinguished by the specified layer parameter.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nextjs, react
- Domain
- build-system, compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100