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

Duplicate SWC Transform For Use Client Components When React Compiler Is Disabled

Next.js with Turbopack passes the same filename to SWC for multiple compilation layers (e.g., RSC and client), causing duplicate entries in SWC AST output and preventing plugins from distinguishing contexts.

mediumConfidence 85%Next.jsServer ActionsRoute HandlersAffected V16.1.6

Origin Analysis

Next.js's compilation workflow transforms the same module (such as a use client component) in multiple layers (RSC, client, etc.), but the filename passed to SWC's TransformContext does not include layer information, leading to identical filenames and ambiguity for SWC plugins.
1. pnpm i 2. npm run build 3. Inspect .swc-plugin-stage-output directory to observe duplicate identical filenames. Environment: Next.js 16.1.6, React 19.2.3, Turbopack enabled, React Compiler disabled.

Fixing Code Block

export function addLayerToFilename(filename: string, layer: string | undefined): string { if (!layer) return filename; const separator = filename.includes('?') ? '&' : '?'; return `${filename}${separator}layer=${layer}`; } // In Next.js SWC transform call site (e.g., next/src/build/swc/index.ts), // apply the function before passing filename to SWC: // const transformedFilename = addLayerToFilename(filename, options.layer); // Then use transformedFilename as the filename in TransformContext.
The fix appends a layer query parameter (e.g., ?layer=app-rsc or &layer=app-client) to the filename before handing it to SWC. This makes filenames unique per compilation layer, allowing SWC plugins to distinguish between duplicate entries. The function handles both cases of existing query strings and no query strings.

Edge Case Audit

SWC plugins that rely on exact filename matches will need to be updated to parse the new layer query parameter. This change may not be compatible with older Next.js versions or external tooling that assumes filenames without query parameters. Rollback: remove the added layer parameter or revert the change in the transform call site. Test across all layer types (RSC, client, edge) to ensure no unintended side effects.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state