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

Optimistic Routes Wrongly Predict Rewritten Pages, Causing Locale Mismatch

When optimisticRoutes is enabled and a path is rewritten (e.g., /team → /en/team), the client applies an optimistic navigation state based on the unrewritten URL. This incorrectly sets the locale (or other dynamic params) to the raw path segment instead of the rewritten value, leading to flashing 404s, wrong data fetching, or transient wrong locale rendering until the server response resolves.

highConfidence 78%Next.jsAffected V16.3.1-Canary.7

Origin Analysis

The optimistic navigation logic uses the original, unrewritten URL to construct the optimistic router state, bypassing server-side rewrite rules. Rewritten paths are therefore not resolved to their actual app routes before the optimistic patch is applied, causing dynamic segments (such as locale) to be derived from the raw pathname.
1. Open the Vercel deployment.\n2. Wait for /de prefetch to complete (page will notify).\n3. Click on 'Team (no prefetch)'.\n4. The page briefly shows a marker that it received the wrong locale ('team' instead of 'en').

Fixing Code Block

Edge Case Audit

This hotfix disables optimisticRoutes globally, so all navigations lose the perceived performance benefit of optimistic UI updates. Users may notice slightly slower route transitions, and high-frequency navigations may increase server load. To roll back, remove or set optimisticRoutes to true in next.config.js after upgrading to a fixed Next.js version. Re-enabling before the upstream fix will restore the original buggy behavior. No data corruption risk, but test in staging before production deployment.

Ecosystem Topology