nextjs - 💡(How to fix) Fix Route handler (route.ts) with static folder name next to [slug] inside nested route groups is matched as slug — regression 16.1.7 → 16.2.0

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…

Error Message

Error: Invariant: failed to find source route /[store]/[lang]/c/sitemap.xml for prerender /[store]/[lang]/c/sitemap.xml

Code Example

app/
└── (group-a)/
    └── [store]/
        └── [lang]/
            └── (group-b)/
                └── c/
                    ├── [slug]/
                    │   └── page.tsx        (export const dynamic = "force-static")
                    └── sitemap.xml/
                        └── route.ts        (export const dynamic = "force-static")

---

export const dynamic = "force-static";
export const revalidate = false;
export const dynamicParams = true;

export async function generateStaticParams() {
  return [];
}

export default async function Page({ params }: { params: Promise<{ store: string; lang: string; slug: string }> }) {
  return <div>page</div>;
}

---

export const dynamic = "force-static";

export async function GET(_: Request, { params: _params }: { params: Promise<{ store: string; lang: string }> }) {
  const { store, lang } = await _params;
  return new Response(`store=${store} lang=${lang}`, { headers: { "Content-Type": "text/xml" } });
}

---

Error: Invariant: failed to find source route /[store]/[lang]/c/sitemap.xml for prerender /[store]/[lang]/c/sitemap.xml

---

[ '%5Bstore%5D', '%5Blang%5D', '%5Bslug%5D' ]

---

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.4.0: Thu Mar 19 19:33:09 PDT 2026; root:xnu-12377.101.15~1/RELEASE_ARM64_T8112
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 22.22.3
  npm: 10.9.8
  Yarn: N/A
  pnpm: 11.1.3
Relevant Packages:
  next: 16.2.6 // Latest available version is detected (16.2.6).
  eslint-config-next: N/A
  react: 19.2.6
  react-dom: 19.2.6
  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/jordihm9/nextjs-repro-94024


To Reproduce

Create a Next.js App Router project with the following structure:

app/
└── (group-a)/
    └── [store]/
        └── [lang]/
            └── (group-b)/
                └── c/
                    ├── [slug]/
                    │   └── page.tsx        (export const dynamic = "force-static")
                    └── sitemap.xml/
                        └── route.ts        (export const dynamic = "force-static")

page.tsx:

export const dynamic = "force-static";
export const revalidate = false;
export const dynamicParams = true;

export async function generateStaticParams() {
  return [];
}

export default async function Page({ params }: { params: Promise<{ store: string; lang: string; slug: string }> }) {
  return <div>page</div>;
}

route.ts:

export const dynamic = "force-static";

export async function GET(_: Request, { params: _params }: { params: Promise<{ store: string; lang: string }> }) {
  const { store, lang } = await _params;
  return new Response(`store=${store} lang=${lang}`, { headers: { "Content-Type": "text/xml" } });
}

Then deploy to Vercel (or run next build with multiple workers).


Current vs. Expected behavior

Expected: [store]/[lang]/c/sitemap.xml is recognized as a standalone route handler and registered in the app output map — as it was in 16.1.7.

Actual — with dynamic = "force-static": build fails with:

Error: Invariant: failed to find source route /[store]/[lang]/c/sitemap.xml for prerender /[store]/[lang]/c/sitemap.xml

Actual — with dynamic = "auto": build succeeds but [store]/[lang]/c/sitemap.xml is not registered in the app output map. At runtime the request is matched against [store]/[lang]/c/[slug] instead, and params arrive URL-encoded:

[ '%5Bstore%5D', '%5Blang%5D', '%5Bslug%5D' ]

instead of the expected { store: 'en', lang: 'en' }.

Additional observations:

  • sitemap.xml may be treated as a keyword. Renaming the folder from sitemap.xml to any arbitrary name (e.g. asd.xml) fixes both the build failure and the param encoding issue. This may indicate sitemap.xml triggers a special path resolution case, though it could also be coincidental given that renaming also avoids the slug collision.

  • Root-level *-sitemap.xml route handlers work fine. Several route handlers at the app root without dynamic parent segments (e.g. product-sitemap.xml/route.ts, collection-sitemap.xml/route.ts) work correctly in all versions. The bug is isolated to sitemap.xml under dynamic parent segments with a sibling [slug] route.

  • A llms.txt route handler at the same [store]/[lang] level works fine. It shares the same dynamic parent segments but has no inner route group and no sibling dynamic [slug]. Both conditions appear necessary to trigger the bug: nested route groups and a sibling [slug] route at the same level.

  • Only consistently reproducible on Vercel (3 parallel build workers). Local next build succeeds in all cases, pointing to a race condition in app output map registration during parallel prerendering.


Environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.4.0: Thu Mar 19 19:33:09 PDT 2026; root:xnu-12377.101.15~1/RELEASE_ARM64_T8112
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 22.22.3
  npm: 10.9.8
  Yarn: N/A
  pnpm: 11.1.3
Relevant Packages:
  next: 16.2.6 // Latest available version is detected (16.2.6).
  eslint-config-next: N/A
  react: 19.2.6
  react-dom: 19.2.6
  typescript: 5.9.3
Next.js Config:
  output: N/A

Which area(s) are affected?

Dynamic Routes, Route Groups, Route Handlers, Turbopack


Which stage(s) are affected?

  • next build (local) — does not reproduce
  • Vercel (Deployed) — reproduces consistently

Additional context

Regression introduced between 16.1.7 (working) and 16.2.0 (broken). All versions from 16.2.0 through 16.2.6 are affected. Downgrading to 16.1.7 resolves the issue immediately.

Deployed on Vercel with Turbopack and 3 parallel build workers. The bug does not reproduce locally (likely single-threaded or fewer workers), which points to a race condition during parallel prerendering in the app output map registration step.

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 - 💡(How to fix) Fix Route handler (route.ts) with static folder name next to [slug] inside nested route groups is matched as slug — regression 16.1.7 → 16.2.0