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

Scroll To Top Not Reset When Navigating Via Proxy 308 Redirect In Production

Client-side navigation through a proxy that responds with a 308 redirect preserves the previous page's scroll position, leaving the new page scrolled down instead of at the top.

highConfidence 72%NextAffected V16.3.4Affected V16.4.0-Canary.14

Origin Analysis

Next.js router's scroll restoration logic likely compares the originally requested pathname (`/about`) with the final resolved pathname (`/en/about`) after following the redirect, failing to detect a route change and therefore not triggering the scroll-to-top effect. This is a design flaw in how the router tracks the canonical URL when a fetch-based navigation is redirected.
1. Clone the reproduction, install dependencies, and start the production build (next build && next start). 2. Open http://localhost:3000/en and scroll to the bottom of the page (3000px tall). 3. Click the link 'Go to /about (relies on proxy 308 -> /en/about)'. 4. Observe that window.scrollY remains ~2540 on the redirected /en/about page instead of 0. 5. Compare with the non-redirected link to /en/about, which correctly resets scroll to 0.

Fixing Code Block

Edge Case Audit

This hotfix overrides the browser's native scroll restoration for normal push navigations. It guards against popstate to preserve back/forward scroll positions, but edge cases with nested routes or concurrent navigations may still occur. If a future Next.js update fixes the underlying bug, remove this component to avoid conflicts. Rollback: delete the component and its usage from the layout.

Ecosystem Topology