rails / rails

Ruby on Rails
https://rubyonrails.org
MIT License
55.8k stars 21.6k forks source link

Infinite loop passing form_builder in partial as local after update to 7.1.3.4 (was 7.0.8.4) #52142

Closed zameo94 closed 2 weeks ago

zameo94 commented 3 months ago

Steps to reproduce

When I try to pass the form_builder to a partial as local, I've got an infinite loop with this error:

Completed 500  in 1701ms (ActiveRecord: 1314.9ms | Allocations: 163362)

SystemStackError (stack level too deep):

app/views/admin/authors/_form.html.erb:357

The code is:

<%= form_for [:admin, @author], html: { class: 'form form-horizontal', multipart: true, style: 'margin-bottom: 0' } do |f| %>
  <%= render partial: 'my_partial', locals: { f: f } %>
<% end %>

I noticed this problem after updating to Rails 7.1.3.4 (was 7.0.8.4)

System configuration

Rails version: 7.1.3.4

Ruby version: 3.3.2

gettinDrikkieWithIt commented 3 months ago

Exactly the same issue for me, rendering any partial gives a stack level to deep when I upgraded to Rails 7.1.3.4 from Rails 7.0.5

zameo94 commented 3 months ago

@gettinDrikkieWithIt only partials with form_builder as locals? the others work for me

ccasabona commented 3 months ago

Try using form_with as form_for and form_tag are soft-deprecated.

zameo94 commented 3 months ago

@ccasabona I tried with form_with, same problem

gettinDrikkieWithIt commented 3 months ago

@zameo94 my partial has basic text inside it, not even a form. And still getting this error

zameo94 commented 3 months ago

@gettinDrikkieWithIt how do you render your partial? can you share the line?

nicho1991 commented 3 months ago

i get the same, it can be boiled down to almost nothing to replicate

= simple_form_for @plane do |form|
  = render 'form_general', locals: { f: form }

and just leave whatever partial empty, in this case _form_general

zameo94 commented 3 months ago

@nicho1991 in my case, when I delete all the references to the form in the partial, it's working

nicho1991 commented 3 months ago

I just found the cause for this!

i had gem 'meta_request' in my Gemfile, this caused the error, after i removed it, i have no issue https://github.com/dejan/rails_panel/issues/180

zzak commented 3 months ago

Thanks for investigating.

I tried to create a repro script, but the test passes. If you are able to alter the script to fail (only using rails) please feel free. It will help us bisect the offending commit, and determine how to fix.

# frozen_string_literal: true

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  gem "rails"
  # If you want to test against edge Rails replace the previous line with this:
  # gem "rails", github: "rails/rails", branch: "main"
end

require "minitest/autorun"
require "action_view"

class BugTest < ActionView::TestCase
  def setup
    @controller.append_view_path "."
  end

  def test_stuff
    partial = <<~ERB
      <%= puts f %>
    ERB

    File.write("_partial.html.erb", partial)

    render inline: <<~ERB
      <%= form_with model: false, url: false do |f| %>
        <%= render(partial: 'partial', locals: { f: f }) %>
      <% end %>
    ERB
  end
end
zameo94 commented 3 months ago

@nicho1991 thanks for your message. Actually, after removing the gem meta_request, the error disappear 🥳

rails-bot[bot] commented 2 weeks ago

This issue has been automatically marked as stale because it has not been commented on for at least three months. The resources of the Rails team are limited, and so we are asking for your help. If you can still reproduce this error on the 7-2-stable branch or on main, please reply with all of the information you have about it in order to keep the issue open. Thank you for all your contributions.