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

[CacheComponents] Stale Redirect Marker In Hidden Activity Route Causes Unintended Full-Page Navigation

When a route that calls redirect() behind Suspense is retained in a hidden React Activity (with cacheComponents enabled), the streamed __next-page-redirect DOM marker remains in the document. The navigate-reducer uses a document-wide getElementById check, so any subsequent same-origin Link click from the active route triggers a hard navigation instead of an SPA transition.

highConfidence 72%Next.jsAffected V16.3.3Affected V16.4.0-Canary.8Affected V16.4.0-Canary.9

Origin Analysis

The navigate-reducer performs a global document.getElementById('__next-page-redirect') check. Because the lookup searches the whole document, it finds the redirect marker inside an inactive Activity subtree that is still part of the DOM (though hidden). This stale marker then incorrectly satisfies the hard-navigation condition, causing an unrelated Link click to perform a full-page navigation.
1. Build and start a Next.js app with cacheComponents enabled. 2. Visit a route that renders a component behind Suspense which calls redirect(). Next streams the #__next-page-redirect marker into the document. 3. Navigate away using <Link>. The previous route is retained in a hidden React Activity. 4. Verify that document.getElementById('__next-page-redirect') still finds the marker in the hidden subtree. 5. Click another unrelated same-origin <Link>. The click performs a full document navigation instead of an SPA navigation.

Fixing Code Block

Edge Case Audit

This fix assumes hidden Activities use display:none or equivalent that removes layout boxes. If a future version uses visibility:hidden or opacity:0 instead, getClientRects() may still return rects and the false positive would persist. Additionally, calling getClientRects() on every navigation may cause layout thrashing; for performance-critical paths, consider caching the active Activity reference or using the Activity-specific hidden attribute. Rollback recommendation: revert to the original document.getElementById check if this change introduces issues with legitimate redirect handling where the marker is not measured as visible.

Ecosystem Topology