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

Turbo frame with advance action makes wrong cache #1008

Open
xiaohui-zhangxh opened this issue Sep 19, 2023 · 3 comments
Open

Turbo frame with advance action makes wrong cache #1008

xiaohui-zhangxh opened this issue Sep 19, 2023 · 3 comments

Comments

@xiaohui-zhangxh
Copy link

xiaohui-zhangxh commented Sep 19, 2023

A normal turbo link click, turbo:before-cache is caching previous page, but if a link targets turbo frame with advance action, it's caching current page which after turbo frame is loaded.

I have commited the simplest repo to show this bug, please see this https://github.com/xiaohui-zhangxh/turbo-frame-cache-bug

this is layout https://github.com/xiaohui-zhangxh/turbo-frame-cache-bug/blob/main/app/views/layouts/application.html.erb

<body class="flex">
    <div class="w-80 border-r">
      <ul>
        <li><%= link_to 'Home', root_path(in_frame: 'y') %></li>
        <li><%= link_to 'Page1 not in frame', pages_page1_path(in_frame: 'n') %></li>
        <li><%= link_to 'Page2 not in frame', pages_page2_path(in_frame: 'n') %></li>
        <li><%= link_to 'Page3 not in frame', pages_page3_path(in_frame: 'n') %></li>
      </ul>
      <turbo-frame target="main_frame">
        <ul>
          <li><%= link_to 'Page1', pages_page1_path(in_frame: 'y') %></li>
          <li><%= link_to 'Page2', pages_page2_path(in_frame: 'y') %></li>
          <li><%= link_to 'Page3', pages_page3_path(in_frame: 'y') %></li>
        </ul>
      </turbo-frame>
    </div>
    <div>
      <%= yield %>
    </div>
  </body>

this is one of page https://github.com/xiaohui-zhangxh/turbo-frame-cache-bug/blob/main/app/views/pages/page1.html.erb

<%= turbo_frame_tag :main_frame, 'data-turbo-action' => :advance do %>
  <h1>Pages#page1 <%= params.to_json %></h1>
  <p>Find me in app/views/pages/page1.html.erb</p>
<% end %>

image

I found this issue from here SimoTod/alpine-turbo-drive-adapter#50

@shiftyp
Copy link
Contributor

shiftyp commented Sep 19, 2023

A more verifiable way for all to see the issue @xiaohui-zhangxh is to add a browser test through playwright to show and test the issue. This also enables verification of an eventual solution. Take a look at #1009 when you get a chance and verify this reproduces your issue

shiftyp added a commit to shiftyp/ts-turbo that referenced this issue Sep 19, 2023
@Intrepidd
Copy link
Contributor

I'm seeing the same issue, temporary fix is to disable the turbo cache via meta tag but it's less than ideal

@xiaohui-zhangxh
Copy link
Author

xiaohui-zhangxh commented Sep 28, 2023

I'm seeing the same issue, temporary fix is to disable the turbo cache via meta tag but it's less than ideal

Finally, the same to my solution, I have to disable turbo cache, otherwise the browser backward action has many werid responses, such as first backward clicking has no change, second backward clicking shows wrong page, alpinejs not working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants