hotwire-livereload icon indicating copy to clipboard operation
hotwire-livereload copied to clipboard

Restoring Scrollposition after editing JS/CSS

Open timteske opened this issue 1 year ago • 2 comments

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

timteske avatar Feb 20 '24 09:02 timteske

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" %>

kirillplatonov avatar Apr 30 '24 10:04 kirillplatonov

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

timteske avatar Jun 19 '24 12:06 timteske

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

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

phallguy avatar Jul 03 '24 18:07 phallguy

Perfekt, that fixed the Problem. Thankyou!

timteske avatar Jul 17 '24 13:07 timteske

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 avatar Sep 17 '24 16:09 jon-sully

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

jon-sully avatar Sep 17 '24 16:09 jon-sully