-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
Refactor the way scroll is saved and restored to avoid premature restoration #47
Refactor the way scroll is saved and restored to avoid premature restoration #47
Conversation
Sounds reasonable and very nice to remove the flaky debounce stuff 👏 |
I would delete stored position right after it was restored. |
This is what I'm doing here, isn't it ? |
Or do you mean actually destroying it rather than setting it to zero ? |
Yes, I mean completely destroy it. When restoring:
|
Looks like a nice simplification! And I agree with @elik-ru suggestion, skipping scroll restoration when there's no stored position is better. |
Makes a lot of sense! Just pushed a commit in this direction. |
Co-authored-by: Kirill Platonov <kirill@platmart.io>
Co-authored-by: Kirill Platonov <kirill@platmart.io>
Thanks @Intrepidd 👏 |
@kirillplatonov any way we can get a release pushed ? Thanks ! |
Published v1.3.1 |
This isn't working for me anymore. Anyone else having the same experience? |
What are you experiencing ? No issues on my end and no more intempestive scroll reset. |
It doesn't seem to save the scroll position when scrolling. If I set it manually, it does restore correctly though. |
I see the problem now - it's because Tailwind builds a new build when I save the view. So it goes
Not sure how to fix this yet. Any thoughts? |
Ah yes ! Actually I have this in my config since I started using this gem :
I rely on only one the builds folder, which is updated when my view changes, through tailwind :) |
|
This is the way tailwind works, it listens to changes in your HTML / rb files to detect tailwind classes used so it can generate its CSS with only the classes you use. |
Only listening to Tailwind, of course! That'll fix it. Might be a helpful thing to add as a note to the Readme? |
This looks like a great solution for Tailwind users! Worth mentioning in the Readme. |
Fully overriding default listen paths is probably not necessary. In #52 I added ability to skip only few default folders that are conflicting with Tailwind: # ...
config.hotwire_livereload.skip_listen_paths << Rails.root.join("app/helpers")
config.hotwire_livereload.skip_listen_paths << Rails.root.join("app/javascript")
config.hotwire_livereload.skip_listen_paths << Rails.root.join("app/views") |
I realised #40 had a side effect where scroll would jump to 0 before each visit.
This seems to be because we listen on
turbo:click
to set the scroll position to0
and we restore it in aturbo:before-visit
event.This looked a bit weird to me, I tried coming up with my own implementation that worked for me in my use cases, but this may be naive and I might be missing some crucial context.
Basically, I chose to store the scroll position only just before a reload is requested, and to restore and reset after a load.
This ensures we always save the position at the right time, negating the need for debounced scroll position etc.