-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: ScrollRestoration does not go to page top when redirecting in an action #9577
Comments
Hm, yeah by default scroll restoration is skipped on submissions, but if you redirect from an action that should probably re-enable it. We would then likely need to add |
@brophdawg11 Thank you !! I am not sure I understood anything. How should I fix this issue in my case ? |
I think it's a bug, so I don't think there's a way to work around it at the moment unfortunately. We'll try to get to it in an upcoming release, but if you or anyone else was interested in taking a stab at a PR, I think the change would happen in Right now, we always disable scroll restoration on submissions: updateState({
...
restoreScrollPosition: state.navigation.formData
? false
: getSavedScrollPosition(location, newState.matches || state.matches),
}); But that's incorrectly including redirects after submissions because the let preventScrollRestoration = (
state.navigation.formData &&
location.pathname + location.search === state.navigation.formAction
);
updateState({
...
restoreScrollPosition: preventScrollRestoration
? false
: getSavedScrollPosition(location, newState.matches || state.matches),
}); |
I have been trying to fix this but to no avail via Is there anything I am missing here? This bug is quite problematic in terms of ux in my app. |
Hi, I encounter the same issue. The fix proposed by @brophdawg11 seems to solve the problem for me so I've made a PR. |
This is now released in a |
Thanks, this release fix my issue 🙂 |
Released in |
What version of React Router are you using?
6.4.3
Steps to Reproduce
The action is called with a
<Form method="patch"/>
Expected Behavior
The action is called and redirect to the url
redirect_route
, but without scrolling to the top... I expected the page to scroll to the top when calling the action (and returning the redirect)Actual Behavior
The action is called and the page redirects to the new route, but without scrolling to the top (it stays at the same place)
The text was updated successfully, but these errors were encountered: