-
Notifications
You must be signed in to change notification settings - Fork 478
Flipping content on Turbo Drive navigation #780
Description
When clicking a link using Turbo Drive, which you do by default when creating a new Rails app, the content is flipping between the current version, the old version and the new version when the content was changed for example by another user.
Imagine a counter that is incremented on every request.
- Counter shows
1 - Click link to the same page
- Counter shows
2 - Click link again
- Counter immediately changes back to
1 - After the response arrives the counter changes to
3
This can be observed especially with slow connections. I created a fresh rails application with the following code to demonstrate the issue:
Controller
def index
session['counter'] ||= 0
end
View
<span><%= session['counter'] += 1 %></span>
<br>
<%= link_to 'Click me!', root_path %>
I used Firefox' Development Tools to simulate a slow connection. This is what happens:
Basically, what I try to achieve is a shared shopping cart with an indicator for how many items are in it which is present on every page. But when navigating the site and someone changes the shopping cart I get this nasty behavior.
It looks like this is an issue with caching. Because when I disable it using
<meta name="turbo-cache-control" content="no-cache">
the issue is gone. However, I think that this behavior is not intended. Why would I want and old version from the cache while waiting for the new version when I already have the current version displayed?
