Next.js 15.5 Bug: middleware.ts Rewrites Silently Break ISR Caching
A developer discovered that using NextResponse.rewrite() in Next.js 15.5 middleware silently disables Incremental Static Regeneration, forcing affected pages to return Cache-Control: private, no-store instead of the expected ISR headers. The bug, tracked as vercel/next.js#83862 and filed in September 2025, occurs because Next.js matches the pre-rewrite path against its route manifest, fails to find a match, and falls back to a no-cache default. The issue went undetected for weeks because only unprefixed locale routes were affected, while prefixed locale routes passed through middleware normally and cached correctly. The developer confirmed there is no variant of NextResponse.rewrite() that avoids the problem, and also found that OpenNext's cache interception workaround caused its own errors during background revalidation. The recommended fix is to move URL rewrites out of middleware entirely and into next.config.mjs using the afterFiles rewrites configuration, which restores normal ISR behaviour without affecting redirects.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in