The issue clearly identifies a bug in HMR handling of interception routes with a proposed fix.
The issue describes a bug where interception routes accumulate invalid entries on every HMR save, causing errors. The fix involves filtering existing interception routes before pushing new ones. The problem is well-documented with reproduction steps and a clear root cause analysis.
https://github.com/aleewains/next-app
npx create-next-app@latestapp/users/@modal/(.)[id]/page.tsx (intercepting route)app/users/@modal/default.tsx (returns null)app/users/[id]/page.tsx (full page)app/users/layout.tsx (renders {children} and {modal} slots)app/users/page.tsxnpm run devhttp://localhost:3000/usersExpected: Interception routes continue working normally after HMR file saves.
Actual: The following error is thrown on every file save:
Error: Invalid interception route: /users/(.)(.)(.)1
Must be in the format /<intercepting route>/(..|...|..)(..)/<intercepted route>
The number of (.) markers increases with each save (1 save = 1 marker,
3 saves = 3 markers), proving entries accumulate. A full dev server restart
is required each time to temporarily resolve it.
Root Cause (investigated):
In setup-dev-bundler.js, interception routes are pushed into beforeFiles
on every HMR update without clearing old entries:
// Runs on EVERY HMR update — never clears!
opts.fsChecker.rewrites.beforeFiles.push(...interceptionRoutes); // BUG
Fix — filter before pushing:
opts.fsChecker.rewrites.beforeFiles = opts.fsChecker.rewrites.beforeFiles
.filter(r => !_generateinterceptionroutesrewrites.isInterceptionRouteRewrite(r));
opts.fsChecker.rewrites.beforeFiles.push(...interceptionRoutes);
This is a regression — Next.js 15.2.4 does not have this code at all and wo
Claim this issue to let others know you're working on it. You'll earn 10 points when you complete it!