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

Segment Prefetch Uses Wrong Route Segment Path For Links After Bandwidth Cap, Causing 404 Under Rewrites

In Next.js 16.3.0, when a page contains links with different route shapes and a middleware rewrite maps some URLs to a different locale prefix, the client-side segment prefetch scheduler reuses the segment path from a previously processed link (e.g., the home route) for later links that are starved by the 4-request network cap. This results in 404 responses for the affected prefetch _rsc requests. Navigation still works due to fallback, but browser consoles are polluted with errors and E2E tests fail.

highConfidence 85%Next.jsAffected V16.3.0-Canary.76Affected V16.3.0Affected V16.3.1-Canary.13

Origin Analysis

The prefetch ordering change in PR #95393 introduced a bug in the segment cache scheduler. When multiple prefetch tasks are queued and the 4-request bandwidth cap starves later tasks, those tasks later get processed but do not retain their own route segment path. Instead, they reuse the segment path from the last successfully processed route (e.g., /$d$locale/__PAGE__ from the /en link) when requesting their own URL, causing a 404 because that segment path does not exist for the catch-all route shape. The issue requires both a rewrite (so the URL resolves to a different route shape) and at least one link to a differently shaped, non-rewritten route.
1. Clone https://github.com/okadriu/next-16-3-segment-prefetch-404 2. Run pnpm install && pnpm build && pnpm start 3. Open http://localhost:3000/ with DevTools Network filtered on _rsc 4. Observe that only the first four links issue a /_tree request; the remaining three links reuse the segment path /$d$locale/__PAGE__ and return 404 for their prefetch requests.

Fixing Code Block

Edge Case Audit

This patch modifies a core internal file and may break if the scheduler structure changes in future Next.js releases. It has not been tested under concurrent prefetching or with cacheComponents/partialPrefetching enabled; it may need adjustment for #96965. Rollback: remove the patch and reinstall the package (`npx patch-package --reverse` or `pnpm install`). Also consider using `prefetch={false}` on the affected non-rewritten links as a temporary workaround until an official fix is released.

Ecosystem Topology