hotwired/turbo-rails

Turbo refresh can hijack user navigation

klevo opened this issue · 3 comments

There is a race condition with Turbo 8 refreshes and regular user clicks through the application.

It's rather easy to observe when there is a consistent stream of refreshes generated and user navigates through the pages steadily.

When a refresh broadcast comes in just after the user click, it overrides the user generated turbo visit and the visitor stays on the same page.

Here's a video of the issue:

turbo-refresh-overriding-user-visit.mov
  • At the end you can observe I click on "Show this item" of the item named "Two", yet I remain on the index page. You can notice the desired page blinked in and out for a few microseconds too.
  • The cause is visible in the console: The second to last turbo visit to /items/2 is my user initiated action.
  • The following (last) entry in the console is the turbo refresh of the current /items page that just arrived (you can see the Updated at times changed from from :05 to :06). This refresh essentially hijacked my click and resulted in me staying on the index page.

This is on Safari 17.4.1. I also replicated the same issue in latest Chrome.

I created a simple Rails 7.1 app to demonstrate the issue that is used in the above video with full instructions.

Thank you for opening this issue. Could this unexpected behavior be resolved by hotwired/turbo#1213?

@seanpdoyle I tested it but unfortunately it does not solve the issue. The problem remains the same.

I figured out the actual issue and the fix, it's the debouncing within Turbo lib itself. I opened a PR there: hotwired/turbo#1250

Therefore I'm closing this issue.