nextjs - ✅(Solved) Fix Duplicate SWC transform for use client components when React Compiler is disabled [1 pull requests, 1 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#90248Fetched 2026-04-08 00:20:30
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
0
Author
Participants
Timeline (top)
cross-referenced ×1issue_type_added ×1labeled ×1

Fix Action

Fixed

PR fix notes

PR #90296: turbopack: pass layer as named query param to SWC transform context

Description (problem / solution / changelog)

Append layer to the filename passed to SWC (TransformContext) so plugins see e.g. app/page.tsx?layer=app-rsc, aligning with next-swc-loader. Use named param "layer=value" (Vite-style) for extensibility; use "&layer=..." when the path already has a query.

<!-- Thanks for opening a PR! Your contribution is much appreciated. To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change(s) that you're making: ## For Contributors ### Improving Documentation - Run `pnpm prettier-fix` to fix formatting issues before opening the PR. - Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide ### Fixing a bug - Related issues linked using `fixes #number` - Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ### Adding a feature - Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas) - Related issues/discussions are linked using `fixes #number` - e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) - Documentation added - Telemetry added. In case of a feature if it's used or not. - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ## For Maintainers - Minimal description (aim for explaining to someone not on the team to understand the PR) - When linking to a Slack thread, you might want to share details of the conclusion - Link both the Linear (Fixes NEXT-xxx) and the GitHub issues - Add review comments if necessary to explain to the reviewer the logic behind a change ### What? ### Why? ### How? Closes NEXT- Fixes # -->

Changed files

  • turbopack/crates/turbopack-ecmascript/src/lib.rs (modified, +7/-0)
  • turbopack/crates/turbopack-ecmascript/src/parse.rs (modified, +20/-2)
  • turbopack/crates/turbopack-ecmascript/src/webpack/parse.rs (modified, +1/-0)
  • turbopack/crates/turbopack-ecmascript/src/webpack/references.rs (modified, +1/-0)

Code Example

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

  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
<img width="425" height="269" alt="Image" src="https://github.com/user-attachments/assets/e67dd612-69a1-42b5-bd35-8e5a4847b46e" /> <img width="565" height="492" alt="Image" src="https://github.com/user-attachments/assets/22ce4793-50d8-4a14-93c6-2a3a7388f775" />

Expected behavior

<img width="541" height="417" alt="Image" src="https://github.com/user-attachments/assets/dec3ed40-59ab-43d5-ab56-652ccfdcfa05" />

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

extent analysis

Fix: Append a layer query‑parameter to the filename passed to SWC

Next.js (v16) feeds the same source file to SWC twice – once for the app layer and once for the rsc layer – without any way for a plugin to tell them apart.
The easiest, non‑breaking fix is to mutate the filename that reaches the SWC transform context:

// file: node_modules/next/dist/compiler/next-swc-loader.ts
// (or copy the file into your repo and point Next to it via a custom loader)

import type { TransformContext } from '@swc/core';

// Helper – add ?layer=… or &layer=… depending on existing query string
function withLayerQuery(original: string, layer: string): string {
  return original.includes('?')
    ? `${original}&layer=${layer}`
    : `${original}?layer=${layer}`;
}

// Patch the function that creates the TransformContext
export function createTransformContext(
  filename: string,
  source: string,
  // …other args
): TransformContext {
  // ---------------------------------------------------------

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