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

Next.Js Build Generates Unnecessary RSC Files For API Route Handlers Causing Deployment Route Limit

When building a Next.js app with route handlers under the app directory, the build output includes .rsc and .rsc.segment files for each API route, doubling the number of routes and causing Vercel deployment failures due to route limits.

highConfidence 85%Next.jsAffected V16.3.1

Origin Analysis

Next.js build pipeline incorrectly treats route handlers (route.ts) as server components pages, generating client navigation RSC payloads (.rsc and .rsc.segment) for them. This is a design flaw in the App Router build process where route handlers are not excluded from RSC generation.
1. Clone https://github.com/davecarlson/nextjs-route-handler-rsc-routes-repro 2. Run npm install 3. Run npm run build 4. Run npm run verify:files Observe that for each route handler such as /api/[tenantId], an additional .rsc file and .rsc.segment file are generated, e.g., /api/[tenantId].rsc and /api/[tenantId].rsc.segment.

Fixing Code Block

Edge Case Audit

This Hotfix assumes all API routes are under app/api and that none of them intentionally return RSC streams. If an API route uses 'text/x-component' content type or depends on RSC serialization, removing these files could break that functionality. Rollback is straightforward: revert the build script change and re-run the build. Test thoroughly in a staging environment before deploying. Also, future Next.js upgrades may change the output directory structure, requiring script update.

Ecosystem Topology