When loading a frame and the response does not have a matching <turbo-frame> with the same id, an error is logged in the console in FrameController#extractForeignFrameElement. It was discussed in this issue #31.
However, I think this causes an issue in most Rails apps.
Steps to reproduce
Let's imagine a simple CRUD controller on a quote resource. The destroy action in the controller would look like this:
# app/controllers/quotes_controller.rb
def destroy
@quote.destroy # Destroy the quote
redirect_to quotes_path # Redirect to index page
end
In the QuotesController#index page, I render the collection of quotes:
<%# app/views/quotes/index.html.erb %>
<%= render @quotes %>
The markup for a quote is in the app/views/quotes/_quote.html.erb partial:
<%# app/views/quotes/_quote.html.erb %>
<%= turbo_frame_tag quote do %>
<div class="quote">
<span>Irrelevant markup</span>
<%= button_to "Destroy", quote, method: :delete %>
</div>
<% end %>
Actual behavior
When clicking on the "Destroy" button for a quote, the quote is removed, but I get an error in console: Response has no matching <turbo-frame id="quote_1"> element. The empty frame remains in the DOM.
Expected behavior
The <turbo-frame id="quote_1"> is removed from the DOM completely. No error is logged in the console.
What do you think?
If you agree with the expected behavior, I would love to make a PR.
If what is expected when destroying a resource is to always distinguish the html and turbo_stream formats, then I would love to document it somewhere:
# app/controllers/quotes_controller.rb
def destroy
@quote.destroy
respond_to do |format|
format.html { redirect_to quotes_path }
format.turbo_stream
end
end
When loading a frame and the response does not have a matching
<turbo-frame>with the sameid, an error is logged in the console inFrameController#extractForeignFrameElement. It was discussed in this issue #31.However, I think this causes an issue in most Rails apps.
Steps to reproduce
Let's imagine a simple CRUD controller on a
quoteresource. The destroy action in the controller would look like this:In the
QuotesController#indexpage, I render the collection of quotes:The markup for a quote is in the
app/views/quotes/_quote.html.erbpartial:Actual behavior
When clicking on the "Destroy" button for a quote, the quote is removed, but I get an error in console:
Response has no matching <turbo-frame id="quote_1"> element. The empty frame remains in the DOM.Expected behavior
The
<turbo-frame id="quote_1">is removed from the DOM completely. No error is logged in the console.What do you think?
If you agree with the expected behavior, I would love to make a PR.
If what is expected when destroying a resource is to always distinguish the
htmlandturbo_streamformats, then I would love to document it somewhere: