Skip to content

Flipping content on Turbo Drive navigation #780

@AmShaegar13

Description

@AmShaegar13

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.

  1. Counter shows 1
  2. Click link to the same page
  3. Counter shows 2
  4. Click link again
  5. Counter immediately changes back to 1
  6. 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:

Screencast from 27 10 2022

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions