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

Next.Js 16.2.X Regression: Sitemap.Xml Route Handler With Dynamic Segments Fails To Register On Vercel Due To Parallel Build Race

A route handler at [store]/[lang]/c/sitemap.xml with force-static fails the build with 'Invariant: failed to find source route', while with dynamic='auto' the route is not registered and requests are incorrectly matched to a sibling [slug] route. The issue is reproducible only on Vercel with parallel build workers, indicating a race condition in app output map registration. Renaming the sitemap.xml folder or using a non-sitemap.xml name avoids the bug.

highConfidence 85%Next.jsAffected V16.2.0Affected V16.2.1Affected V16.2.2Affected V16.2.3Affected V16.2.4Affected V16.2.5Affected V16.2.6

Origin Analysis

Next.js route manifest generation has a race condition when multiple build workers process nested route groups containing a route handler named sitemap.xml alongside a sibling dynamic [slug] route. The static analysis for sitemap.xml appears to trigger a special path resolution that is not synchronized across parallel prerendering tasks, causing the route to be omitted from the app output map or missing during source route lookup.
1. Create a Next.js 16.2.x project with app router. 2. Add a route handler at app/[store]/[lang]/c/sitemap.xml/route.ts with export const dynamic = 'force-static' (or 'auto'). 3. Add a sibling dynamic route at app/[store]/[lang]/c/[slug]/page.tsx. 4. Deploy to Vercel (3 parallel build workers). 5. Observe build failure with force-static or missing route registration with auto, leading to URL-encoded params from the [slug] route.

Fixing Code Block

Edge Case Audit

The rewrite rule may conflict with other rewrites or dynamic route matching if not placed with proper priority. Since the destination path contains dynamic segments, it will undergo matching again—ensure no other route captures /sitemap-xml. This workaround is a temporary fix; once Next.js resolves the underlying race condition, the rewrite and directory rename should be reverted to avoid unintended behavior. Test thoroughly on Vercel and local builds, as rewrite behavior may differ across platforms. Keep a backup of the original directory name and config for easy rollback.

Ecosystem Topology