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

Prevent silent restoration visits when previous visit request is in-flight #595

Conversation

domchristie
Copy link
Contributor

@domchristie domchristie commented May 26, 2022

Silent Visits don't dispatch events. A Visit is deemed to be silent if its location is on the current page. Prior to this commit, this is determined by checking the last rendered location. This approach can result in false positives if a Visit is interrupted and never gets rendered. For example, tapping a link, then immediately navigating back, will be incorrectly considered a same-page visit. Checking the previous location using window.location is also not possible on Back/Forward because it is changed before the popstate event, so by the time a new Visit is created, the location has already changed.

This commit accurately compares the last visited location by storing a reference to the lastVisit on the Navigator, falling back to the View's lastRenderedLocation.

Fixes #594

…light.

Silent Visits don't dispatch events. A Visit is deemed to be silent if its location is on the current page. Prior to this commit, this is determined by checking the last rendered location. This approach can result in false positives if a Visit is interrupted and never gets rendered. For example, tapping a link, then immediately navigating back, will be incorrectly considered a same-page visit. Checking the previous location using `window.location` is also not possible on Back/Forward because it is changed _before_ the popstate event, so by the time a new Visit is created, the location has already changed.

This commit accurately compares the last visited location by storing a reference to the `lastVisit` on the Navigator, falling back to the View's `lastRenderedLocation`.
@domchristie domchristie force-pushed the fix_same_page_visit_definition_for_restoration_visits branch from 8fb31c7 to a651d32 Compare May 26, 2022 17:47
@dhh dhh merged commit 2e344b3 into hotwired:main Jun 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

turbo:visit is not dispatched then navigating Back whilst a request is in flight
2 participants