Page scrolled back to the top when redirecting to same the page from useFetcher Form
See original GitHub issueWhat version of Remix are you using?
1.4.1
Steps to Reproduce
Submit a form from useFetcher
import type { ActionFunction } from '@remix-run/node';
import { redirect } from '@remix-run/node';
import { useFetcher } from '@remix-run/react';
export const action: ActionFunction = () => {
return redirect('/test');
};
export default function Test() {
const fetcher = useFetcher();
return (
<div>
<fetcher.Form method="post" style={{ marginTop: '150vh' }}>
<button type="submit">Submit</button>
</fetcher.Form>
</div>
);
}
Expected Behavior
Page should stay at the same scroll position
Actual Behavior
Page is scrolled to the top
Issue Analytics
- State:
- Created a year ago
- Reactions:6
- Comments:5
Top Results From Across the Web
Angular and scroll to top when redirect - Stack Overflow
Is there in angular something like scrolling to top of website while url change is detected? If not, how to scroll to the...
Read more >Main Concepts v6.6.1 - React Router
There are a lot of different ideas around routing from back and front end frameworks. ... Hashes in URLs indicate a scroll position...
Read more >How to make your page scroll to the top when route changes?
Explanation: We initialize a variable by the name routePath and store the value of the current URL in it which is returned with...
Read more >React Router 6.4 - Getting Started - YouTube
Get started with React Router 6.4, learn how it differs from 6.x and how you can use its amazing new data-fetching (and submission)...
Read more >React Scroll to Top on Page Change with React Router
Learn how to make your page scroll to the top whenever you change routes in React using React Router. If you want to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ve added a PR which fixes the problem for me but I don’t know if it’s what the Remix team will want.
Also fixed the PR to use my actual personal account and not my work one 😦
This is for JS/non-JS support where I’m using the same action. In the non-JS version I want a redirect whereas in the JS version I want to stay on the same page, the logic is close the the Newsletter Sign Up example.
As far as I’m aware useFetcher will redirect if it recieves a redirect response but I don’t think it should if you’re on the same page. By the looks of it this is the funcionality of a normal
Form
submission see here.I could write some custom logic to only return a redirect if I provide a certain field but that feels messy.