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

Pages Router: Shallow GetRouteInfo Returns __AppRouter Prefetch Marker Causing App Crash

In Next.js Pages Router, during a shallow navigation, Router.getRouteInfo() may return a cached { __appRouter: true } prefetch marker instead of actual route info, leading to undefined Component and pageProps, crashing _app and preventing navigation.

highConfidence 95%Next.jsAffected V16.3.3Affected V16.3.4Affected V16.4.0-Canary.13

Origin Analysis

Router.getRouteInfo() returns cached route info for shallow navigations without verifying that the cached entry is valid route info. The __appRouter prefetch marker (stored in this.components) is not filtered out, so it flows into the render path, causing React to receive undefined Component and pageProps.
1. Open a Pages Router dynamic route page (e.g., /players/alice) in development or production. 2. In browser console, run: window.beforeNav = 1; window.next.router.components['/players/[name]'] = { __appRouter: true }; window.next.router.push('/players/[name]?tab=stats', '/players/alice?tab=stats', { shallow: true }). 3. Observe that no navigation occurs (window.beforeNav remains 1) and the app crashes with TypeError or 'Element type is invalid'.

Fixing Code Block

Edge Case Audit

This change may cause additional network requests or hard navigations in scenarios where a stale marker is encountered, but prevents crashes. Ensure that other code paths that write the marker are also fixed to avoid repeated fetch loops. Rolling back this change will reintroduce the crash; to rollback, revert the file changes and redeploy. The check relies on the marker property being '__appRouter' with any value; if future Next.js versions change the marker shape, this guard may need updating.

Ecosystem Topology