Skip to content
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

useFetcher().Form always scrolls to the top on submit, Form doesn't #4265

Closed
itsMapleLeaf opened this issue Sep 22, 2022 · 4 comments
Closed
Assignees
Labels
bug Something isn't working feat:scroll Issues related to scroll restoration

Comments

@itsMapleLeaf
Copy link
Contributor

What version of Remix are you using?

1.7.2

Steps to Reproduce

git clone https://github.com/itsMapleLeaf/remix-fetcher-scrolls-to-top
cd remix-fetcher-scrolls-to-top
pnpm install
pnpm dev

Scroll down a bit, and see the difference in behavior between <Form> and the fetcher form

Expected Behavior

The fetcher form shouldn't scroll to the top. Ideally, the behavior should be configurable

Actual Behavior

The fetcher form scrolls to the top

@emilbryggare
Copy link
Contributor

Same for me, I created a repo similar to @itsMapleLeaf before I found this issue. I expanded on it a bit more submitting with either Form, useSubmit, fetcher.Form and fetcher.submit and returning either json or redirect from the action.

What version of Remix are you using?

1.7.6

Steps to Reproduce

git clone https://github.com/emilbryggare/remix-fetcher-scrolls-to-top-2
cd remix-fetcher-scrolls-to-top-2
npm install
npm dev
Scroll down a bit, and see the difference in behavior when submitting with either Form, useSubmit, fetcher.Form and fetcher.submit and returning either json or redirect from the action.

Expected Behavior

The fetcher.form and fetcher.submit shouldn't scroll to the top. Ideally, the behavior should be configurable

Actual Behavior

The fetcher.form and fetcher.submit scrolls to the top

@machour
Copy link
Collaborator

machour commented Nov 24, 2022

@itsMapleLeaf Thank you for opening this issue 🍁
I think it's the same as #3145, but I'm keeping both open for the repros here.

@emilbryggare Can you try again with #3165 applied and see if everything works as expected? 🙏🏼

@machour machour added bug Something isn't working and removed bug:unverified labels Nov 24, 2022
@emilbryggare
Copy link
Contributor

@machour Sure! After applying the patch (in version 1.7.6), all scenarios in my reproduction worked as expected. 👍

@machour machour added the feat:scroll Issues related to scroll restoration label Dec 1, 2022
@brophdawg11 brophdawg11 self-assigned this Aug 3, 2023
@brophdawg11
Copy link
Contributor

brophdawg11 commented Aug 7, 2023

By default scroll position will be reset on action submissions if the submission redirects, since it's sending you to a "new" location. You can disable this via the preventScrollReset prop on Form/fetcher.Form.

Related: remix-run/react-router#9886

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working feat:scroll Issues related to scroll restoration
Projects
No open projects
Status: Closed
Development

No branches or pull requests

4 participants