Repository navigation
|
We recently bumped from 16.2.11 to 16.3.3. We started seeing that Links which previously scrolled to top in the target page, no longer does that when there is a redirect involved in proxy.ts. So what we do is, const { pathname, search } = req.nextUrl if (!localeFromPath) { When then coming to the redirected page, the current scroll position from the source page is kept. Is this intentional or is it a bug? |
Replies: 5 comments 4 replies
|
Hi — have you reproduced this on a minimal app? I think the issue you are seeing is likely, #96855 — so not necessarily caused by the proxy redirect, rather because of a parallel route with a fixed element. Could you verify please? |
This comment was marked as low quality.
This comment was marked as low quality.
|
this is a regression in how 16.3 handles scroll position during replaceState transitions. in 16.2 the scroll manager treated all navigations the same and reset to top. in 16.3 they changed it so that replaceState transitions (which is what a 308 redirect triggers internally) preserve the current scroll offset. the idea was probably to improve UX for in-page state changes where you dont want the page jumping, but it broke the case where a redirect is used for locale prefixing since thats semantically a new page navigation, not a state replacement. the simplest fix until #98172 lands is switching from redirect to rewrite in your middleware if (!localeFromPath) { rewrite handles the routing server side without sending a 308 back to the browser, so the scroll manager never sees a replaceState. it treats it as a normal forward navigation and resets to top. the browser URL still shows the locale prefixed path since thats what the rewrite resolves to. this also has the side benefit of removing one network roundtrip since the browser no longer has to follow the 308 before getting the actual page. we switched to this pattern for the same reason and it works without needing any client side scroll workarounds. |
Opened, #98172 to track the issue