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

Preserve scroll position when navigating back to talks #408

Merged
merged 1 commit into from
Nov 17, 2024

Conversation

adrienpoly
Copy link
Owner

Problem

Currently, when users scroll down, navigate to a talk, and then return, the scroll position is not preserved. This creates a suboptimal UX: users lose their place on the page, which can be frustrating. Additionally, it causes a jarring visual effect during the page transition, where the talk image quickly snaps to the bottom of the page.

Solution

This PR introduces a mechanism to preserve the scroll position when navigating back via the app’s back button. Note that handling the browser's native back button will require a different solution (see Hotwired Turbo issue #37 for potential approaches).

Implementation

  • Back URL Rewriting: On hover, we dynamically rewrite the back_to URL to include the current scroll position.
  • Scroll Restoration: A Stimulus controller reads the scroll_top position from the URL parameters and restores the scroll position when the user returns to the previous page.

This ensures a smoother and more intuitive user experience when navigating between talks.

Demo

CleanShot.2024-11-15.at.08.56.00.mp4

@adrienpoly adrienpoly requested a review from marcoroth November 15, 2024 08:06
@adrienpoly adrienpoly merged commit d99e1fb into main Nov 17, 2024
5 checks passed
@adrienpoly adrienpoly deleted the preserve-scroll-back-to branch November 17, 2024 21:42
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.

1 participant