Skip to content

Error is logged in console when response has no matching <turbo-frame> #432

@alexandreruban

Description

@alexandreruban

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

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