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

Restoring Scrollposition after editing JS/CSS #56

Closed
timteske opened this issue Feb 20, 2024 · 6 comments
Closed

Restoring Scrollposition after editing JS/CSS #56

timteske opened this issue Feb 20, 2024 · 6 comments

Comments

@timteske
Copy link

Hi,
i have an issue with the scroll position.
After editing my JS or CSS Code it reloads the page without scrolling to the restored scroll position.
I only changed the listen_paths of the gem because im using postcss to:
config.hotwire_livereload.disable_default_listeners = true
config.hotwire_livereload.listen_paths = [Rails.root.join("app/assets/builds")]
My console output:
scroll_position

@kirillplatonov
Copy link
Owner

Could you please try disabling data-turbo-track for CSS like @mikker mentioned in #59?

+ <%= stylesheet_link_tag "application", "data-turbo-track": Rails.env.production? ? "reload" : "" %>
- <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>

@timteske
Copy link
Author

Okay i understand but now it restores the old styling and overwrite it with the new.
That's working for changes of styling but when you removing some, it's not working.
restoring_styles

@phallguy
Copy link

phallguy commented Jul 3, 2024

Had the same issue myself. Turbo now has a dynamic option that worked for me.

<%= stylesheet_link_tag "application", "data-turbo-track": "dynamic" %>

@timteske
Copy link
Author

Perfekt, that fixed the Problem. Thankyou!

@jon-sully
Copy link

jon-sully commented Sep 17, 2024

Switching to dynamic solved my gripe! I think that's actually better than the "are you in dev?" current setup

EDIT: my problem being my scroll resetting to the top of the page any time my Tailwind styles rebuilt

@jon-sully
Copy link

I wish there was a way to do some neat magic with Javascript to prevent reloads, but unfortunately when using import maps they bake in the turbo reload tag:

https://github.com/rails/importmap-rails/blob/cc7142e9996d441aa726eb6e013de29ff990ff60/app/helpers/importmap/importmap_tags_helper.rb#L15

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

No branches or pull requests

4 participants