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

Turbopack Pages Router Route Loader Times Out Before Page Registration Despite Successful Chunks

With Pages Router and Turbopack in production, when static chunks are served from a separate assetPrefix origin and page registration chunks are delayed, pageLoader.loadPage() rejects with 'Route did not complete loading' even though all static chunk requests returned 200. This causes client-side navigation to fall back to full document loads.

highConfidence 78%Next.jsAffected V16.3.0-Canary.19

Origin Analysis

The route loader applies a fixed timeout for page registration after initiating chunk loads, but Turbopack may deliver the registration chunk (which calls window.__NEXT_P.push) asynchronously and later than the timeout threshold. The loader does not distinguish between successful chunk loading with delayed registration and actual chunk failure, leading to false timeouts.
1. Clone https://github.com/Stanzilla/next-turbopack-pages-router-route-loader-repro 2. Run `pnpm install` 3. Run `pnpm repro` 4. Observe the command exits non-zero after pageLoader.loadPage() rejects for several Pages Router routes. The probe shows chunkLoaderCallsForRoute: 1, nextPCallsForRoute: 0, entrypointCallsForRoute: 0, while all static chunk responses are 200.

Fixing Code Block

Edge Case Audit

This hotfix may cause pages to hang indefinitely if a registration chunk is genuinely missing or fails to execute after static chunks load, as the fallback timeout is bypassed. In concurrent navigations, multiple overwrites of window.__NEXT_P.push could interfere if not properly managed. On browsers without window.__NEXT_P, the code will throw. Rollback advice: revert to the original fixed-timeout implementation and instead extend the timeout duration or provide a more granular error distinction. Monitor for memory leaks from lingering event listeners in long-lived SPAs.

Ecosystem Topology