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

Clear turbo cache before visiting to avoid unwanted snapshot restoration #53

Merged
merged 1 commit into from
Mar 25, 2024

Conversation

Intrepidd
Copy link
Contributor

@Intrepidd Intrepidd commented Jan 15, 2024

I realised that when working on some elements of a webpage that are below the fold, the first livereload would perform perfectly, but for the subsequent ones, the page would jump to the top before restoring the scroll, which is unexpected and very unsettling.

I tracked it down to the turbo cache, turbo is trying to show the snapshot for the current page while the request is performing, but it does not make sense as we will restore scroll just after.

I see 2 possible solutions :

  • Try to restore the scroll earlier, just after the snapshot is loaded, and make sure it stays at the right value after the new document is shown
  • Clear the cache before visiting, so no snapshot is restored

This PR implements solution #2, I believe as we are trying to reload the page after a change on the code, having a snapshot of the page makes no sense.

@Intrepidd
Copy link
Contributor Author

@kirillplatonov any opinion on this ? 🙏

Copy link
Owner

@kirillplatonov kirillplatonov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Thank you for the PR 👍

@kirillplatonov kirillplatonov merged commit 57db695 into kirillplatonov:main Mar 25, 2024
1 check passed
@Intrepidd
Copy link
Contributor Author

Intrepidd commented Mar 27, 2024

@kirillplatonov thanks so much ! Could you release a new version to spread the love ?

@kirillplatonov
Copy link
Owner

Sure, published v1.3.2: https://github.com/kirillplatonov/hotwire-livereload/releases/tag/v1.3.2

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.

None yet

2 participants