nextjs - ✅(Solved) Fix [Webpack] Route Handlers generate client-reference-manifest.js containing unrelated client components [1 pull requests, 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#88316Fetched 2026-04-08 02:05:05
View on GitHub
Comments
1
Participants
2
Timeline
8
Reactions
0
Author
Timeline (top)
labeled ×2referenced ×2closed ×1commented ×1

Fix Action

Fixed

PR fix notes

PR #88419: fix(build): prevent route handler manifests from inheriting unrelated client components

Description (problem / solution / changelog)

Summary

Fixes #88316

Route handlers (API routes) were generating bloated client-reference-manifest.js files containing unrelated client components from pages when using Webpack. This was caused by the manifest merging logic in flight-manifest-plugin.ts which inherited manifests from all parent path segments.

Changes

  • Modified flight-manifest-plugin.ts to detect route handlers (/route$ pattern)
  • Route handlers now only get their own group's manifest, skipping parent manifest inheritance
  • Pages continue to inherit manifests from parent layouts as before

Why this works

Route handlers:

  • Don't render React components
  • Return Response objects, not JSX
  • Don't need client component references from parent layouts/pages

Turbopack already handles this correctly by doing targeted module graph traversal per entry. This fix aligns Webpack's behavior.

Test Plan

Added test suite test/production/app-dir/route-handler-manifest-size/:

  • Verifies pure route handlers don't include unrelated page client components
  • Verifies pages still include their client components
  • Verifies route handlers with direct client imports don't get page components
  • Tests pass for both Webpack and Turbopack

Changed files

  • AGENTS.md (modified, +1/-0)
  • packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts (modified, +19/-5)
  • test/production/app-dir/route-handler-manifest-size/app/api-with-client/client-utils.ts (added, +6/-0)
  • test/production/app-dir/route-handler-manifest-size/app/api-with-client/route.ts (added, +14/-0)
  • test/production/app-dir/route-handler-manifest-size/app/api/hello/route.ts (added, +6/-0)
  • test/production/app-dir/route-handler-manifest-size/app/components/Button.tsx (added, +12/-0)
  • test/production/app-dir/route-handler-manifest-size/app/components/Dropdown.tsx (added, +36/-0)
  • test/production/app-dir/route-handler-manifest-size/app/components/Modal.tsx (added, +21/-0)
  • test/production/app-dir/route-handler-manifest-size/app/layout.tsx (added, +11/-0)
  • test/production/app-dir/route-handler-manifest-size/app/page.tsx (added, +19/-0)
  • test/production/app-dir/route-handler-manifest-size/route-handler-manifest-size.test.ts (added, +123/-0)

Code Example

Operating System:
  Platform: darwin
  Arch: arm64
Binaries:
  Node: 20.x
  pnpm: 10.x
Relevant Packages:
  next: 16.1.1
  react: 19.2.3
  react-dom: 19.2.3

---

grep -o 'components/[^"]*' ".next/server/app/(backend)/api/hello/route_client-reference-manifest.js" | sort | uniq

---

# UI components found in pure backend API route manifest:
components/Accordion.tsxShould NOT be here
components/Button.tsxShould NOT be here  
components/Dropdown.tsxShould NOT be here
components/Modal.tsxShould NOT be here
components/Tabs.tsxShould NOT be here
RAW_BUFFERClick to expand / collapse

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
Binaries:
  Node: 20.x
  pnpm: 10.x
Relevant Packages:
  next: 16.1.1
  react: 19.2.3
  react-dom: 19.2.3

Which area(s) of Next.js are affected?

App Router, Route Handlers (API routes), Webpack, Build Output

Link to the code that reproduces this issue

https://github.com/arvinxx/next-webpack-api-route-manifest-issue

To Reproduce

  1. Clone the reproduction repo
  2. Run pnpm install
  3. Run pnpm build (uses --webpack flag)
  4. Inspect the API route manifest:
    grep -o 'components/[^"]*' ".next/server/app/(backend)/api/hello/route_client-reference-manifest.js" | sort | uniq

Current Behavior

When using Webpack bundler, pure backend API Route Handlers (route.ts) that import zero client components still generate a route_client-reference-manifest.js containing all client components from the entire application.

Evidence from build output:

# UI components found in pure backend API route manifest:
components/Accordion.tsx    ❌ Should NOT be here
components/Button.tsx       ❌ Should NOT be here  
components/Dropdown.tsx     ❌ Should NOT be here
components/Modal.tsx        ❌ Should NOT be here
components/Tabs.tsx         ❌ Should NOT be here

The API routes (/api/hello, /api/webhook, /api/data) are pure server-side code with no client component imports.

Note: This issue does NOT occur with Turbopack, which correctly generates empty manifests for API routes.

Expected Behavior

When using Webpack, Route Handlers that don't import any client components should either:

  1. Not generate a client-reference-manifest.js at all, or
  2. Generate a minimal manifest containing only Next.js internal components, or
  3. Share a single manifest file instead of duplicating per route

Comparison

BundlerAPI Route ManifestBehavior
Webpack~7KB (contains ALL components)❌ Bug
Turbopack~300B (empty clientModules: {})✅ Correct

Impact

In large production applications using Webpack with many API routes and rich UI libraries, this causes:

  • ~3MB manifest per API route (in our production app with icon libraries)
  • ~220MB total duplicate manifests for 74 API routes
  • Slower serverless cold starts due to loading unused client component mappings
  • Increased build output size

Why Webpack?

Some projects cannot migrate to Turbopack due to:

  • Custom webpack plugins (e.g., react-scan/react-component-name/webpack)
  • Specific webpack configurations not yet supported in Turbopack
  • Legacy dependencies requiring webpack-specific handling

Additional Context

The reproduction repo includes:

  • pnpm build - builds with Webpack (shows the bug)
  • pnpm build:turbo - builds with Turbopack (works correctly)

This allows easy comparison of the two bundlers' behavior.

extent analysis

TL;DR

The issue can be mitigated by using Turbopack instead of Webpack for bundling, as Turbopack correctly generates empty manifests for API routes.

Guidance

  • Investigate the feasibility of migrating to Turbopack, as it does not exhibit the same issue with generating unnecessary client component manifests for API routes.
  • If migration to Turbopack is not possible, consider exploring custom Webpack configurations or plugins that could potentially optimize the generation of client-reference-manifests for API routes.
  • Review the reproduction repository provided to understand the difference in behavior between Webpack and Turbopack and to test potential fixes.
  • Analyze the specific requirements and constraints that prevent the migration to Turbopack, such as custom Webpack plugins or configurations, to identify potential workarounds.

Example

No specific code example is provided due to the complexity of the issue and the need for a more in-depth analysis of the project's configuration and dependencies.

Notes

The provided reproduction repository offers a clear comparison between the behavior of Webpack and Turbopack, which can be useful for further investigation and testing of potential solutions. However, without more specific details about the project's dependencies and configurations, it's challenging to provide a direct fix for the Webpack issue.

Recommendation

Apply workaround: Use Turbopack for bundling if possible, as it correctly handles API route manifests. If Turbopack is not an option, further investigation into custom Webpack configurations or plugins is recommended to mitigate the issue.

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 - ✅(Solved) Fix [Webpack] Route Handlers generate client-reference-manifest.js containing unrelated client components [1 pull requests, 1 comments, 2 participants]