question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Page scrolled back to the top when redirecting to same the page from useFetcher Form

See original GitHub issue

What 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:open
  • Created a year ago
  • Reactions:6
  • Comments:5

github_iconTop GitHub Comments

1reaction
Mattintoncommented, May 11, 2022

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 😦

1reaction
MattKintonCinchcommented, May 10, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found