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

Reload Lazy-loading Turbo Frames #58

Open
tonysm opened this issue Jan 1, 2025 · 4 comments
Open

Reload Lazy-loading Turbo Frames #58

tonysm opened this issue Jan 1, 2025 · 4 comments
Labels
bug Something isn't working need reproduction details We need more information to reproduce

Comments

@tonysm
Copy link

tonysm commented Jan 1, 2025

I have a page with a lazy-loading Turbo Frame on it, and when the content reloads, the frame gets replaced with the placeholder from the main page. Would it be preferred to reload any lazy-loaded frames on the page so their changes (if any) are reflected too?

@tonysm
Copy link
Author

tonysm commented Jan 1, 2025

Setting the html-reload-method to replace does trigger the reloading of Turbo Frames. I guess the question is if we want to do that for the morph option too.

@jorgemanrubia
Copy link
Member

Hey Tony, with morph it should reload the turbo-frames too. I have tested this myself on one of our apps. Since morph replaces the "connected" attribute of the turbo frame, that triggers a reconnect. Are you getting a different behavior here?

@jorgemanrubia jorgemanrubia added bug Something isn't working need reproduction details We need more information to reproduce labels Jan 25, 2025
@tonysm
Copy link
Author

tonysm commented Jan 27, 2025

Oh, I've just tested again and looks like it's working. It might have been something on my end, sorry.

@tonysm tonysm closed this as completed Jan 27, 2025
@tonysm tonysm reopened this Jan 27, 2025
@tonysm
Copy link
Author

tonysm commented Jan 27, 2025

I think I found the issue. It works when we're not using full URL in the src attribute. So, if the Turbo Frame's src attribute points to /messages/new, for instance, it works because the Turbo Frame will replace the src attribute (expanding it) with the full URL http://localhost:3000/messages/new which triggers the lazy-loading Turbo Frame due to the src attribute changing. If we use the full URL from the first render (so the lazy-loading Turbo Frame already starts with src="http://localhost:3000/messages/new"), the lazy-loading Turbo Frame never activates again when the page morphs. Example:

<p style="color: green"><%= notice %></p>

<% content_for :title, "Messages" %>

<h1>Messages</h1>

<div id="messages">
  <% @messages.each do |message| %>
    <%= render message %>
    <p>
      <%= link_to "Show this message", message %>
    </p>
  <% end %>
</div>

<%= turbo_frame_tag "create_message", src: "http://localhost:3000/messages/new" do %>
  <%= link_to "New hello", new_message_path %>
<% end %>

Not sure if this is an actual issue, as I only found out because I'm porting this to Laravel, and in there the URL helpers generate the full URL, but in Rails the new_messages_path helper appears to default to the URI path (relative) instead of full URL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working need reproduction details We need more information to reproduce
Development

No branches or pull requests

2 participants