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

Restore scroll position after reload #40

Merged
merged 4 commits into from
Oct 11, 2023

Conversation

mikker
Copy link
Contributor

@mikker mikker commented Aug 7, 2023

Saves scroll position after scroll events and restores it after updates. Hat tip to @tomazzlender's implementation.

Spent way too long debugging an issue where it would reset without a scroll event. Turned out I had two windows open setting each their own scroll value. So that's sort of a thing but not sure it's something we can fix.

  • Do we want this to be togglable with a config option?

Closes #1

@tomazzlender
Copy link

Thanks for putting effort into the PR! ❤️

Do we want this to be togglable with a config option?

That would be sweet. I noticed that sometimes I need to turn it off due to some circumstances, perhaps others will find themselves in such situations too and will welcome the option.

@mikker
Copy link
Contributor Author

mikker commented Sep 21, 2023

@kirillplatonov Still using this fork in my app and I don't seem to have any critical issues. Can we merge it and release?

@kirillplatonov kirillplatonov merged commit 13a1b3e into kirillplatonov:main Oct 11, 2023
1 check passed
@kirillplatonov
Copy link
Owner

Hey @mikker. Thank you for that PR and sorry for delay with review. It looks and works great. I will publish v1.3 with this feature shortly.

@timteske
Copy link

timteske commented Oct 11, 2023

Hi, do i need to enable this functionality or need to configure something?
Find the Error, i use turbo_stream as reload_method. Using the default fixed my problem.
Thanks for this Epic Feature!

@kirillplatonov
Copy link
Owner

No need to enable anything. It should work out of the box in v1.3.0.

@Intrepidd
Copy link
Contributor

This PR causes an issue for me : each time I click on a link, the scroll resets to 0 before the next page is loaded.

This seems to be because the click event resets scroll to 0, and then the turbo:before-visit event restore the scroll position, so to 0.

@Intrepidd
Copy link
Contributor

Shouldn't we use turbo:visit event rather than turbo:click ? to make sure we reset the scroll position after and not before the visit has occured ? Happy to open a PR if that sounds like a good solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Restore scroll position after reload
5 participants