Skip to content

fix(dev): clear stale interception rewrites on HMR update to prevent accumulation#91364

Open
aleewains wants to merge 4 commits intovercel:canaryfrom
aleewains:canary
Open

fix(dev): clear stale interception rewrites on HMR update to prevent accumulation#91364
aleewains wants to merge 4 commits intovercel:canaryfrom
aleewains:canary

Conversation

@aleewains
Copy link

@aleewains aleewains commented Mar 14, 2026

What

Fixes interception routes breaking on every HMR file save in Next.js 16.

Why

In setup-dev-bundler.ts, interception route rewrites are pushed into
beforeFiles on every HMR aggregated event without clearing old entries
first. The (.) markers stacking up on every save makes dev pretty painful since you have to do a full refresh each time. This causes entries to accumulate on every save:

  • Save No.1 → [(.)users/[id]]
  • Save No.2 → [(.)users/[id], (.)users/[id]]
  • Save No.3 → [(.)users/[id], (.)users/[id], (.)users/[id]]

The duplicate rewrites corrupt pathname matching, producing paths like
/users/(.)(.)(.)1, which then throws:

Error: Invalid interception route: /users/(.)(.)(.)1

How

  1. Added isInterceptionRouteRewrite() helper to
    generate-interception-routes-rewrites.ts — identifies rewrites
    generated from interception routes by checking for the NEXT_URL
    header in the has array.

  2. In setup-dev-bundler.ts, filter out stale interception rewrites
    before pushing fresh ones on each HMR update.

Testing

  • Confirmed broken in 16.1.6 without fix
  • Confirmed working after fix applied to node_modules
  • This is a regression — Next.js 15.2.4 did not have this code path

Closes #91265

@aleewains
Copy link
Author

Hi, I'm an external contributor and the CI checks require maintainer
approval to run. Could someone please trigger the workflows? Happy to
make any changes needed after review. Thanks!

@aleewains
Copy link
Author

I've added a regression test that simulates 3 HMR file saves and
verifies the interception route still works correctly afterwards.
Could a maintainer please trigger CI? Happy to adjust anything needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Interception routes break on every HMR save in Next.js 16 — "Invalid interception route" error

2 participants