Fix stale refresh URL caused by debouncing #1250
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There is a race condition with Turbo 8 refreshes and regular navigation through the application, caused by passing the URL to be refreshed into the debounced function.
If user visits another page, in between the page refresh arriving and the debounced refresh execution, the stale URL in the debounced refresh will navigate back to the page the user just came from.
This behavior is most apparent when there is a steady stream of turbo refreshes coming in and user is navigating through pages that receive these refreshes, but could happen at any (low) volume of page refreshes, if the timing is right.
Here's a video of the issue:
turbo-refresh-overriding-user-visit.mov
/items/2
is my user initiated action./items
page that just executed after the default debounce delay (you can see the Updated at times changed from from :05 to :06). This refresh essentially hijacked my click and resulted in me being returned to 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.