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
Ignore implicit locals if not declared by templates with strict locals #49782
Conversation
Fix: rails#49780 Fix: rails#49761 `CollectionRenderer` implictly inject `<name>_counter` and `<name>_iteration` locals, but in the overwhelming majority of cases they aren't used. So when the rendered template has strict locals we shouldn't require these to be declared, and if they aren't we should simply not pass them. Co-Authored-By: HolyWalley <yakau@hey.com>
Ignore implicit locals if not declared by templates with strict locals
yeah, no problem, haven't noticed that we can use existing call to |
@byroot so now how can we pass Follow the line in changelog: If magic comment is: Tried some other ways with |
@longstackup it should work yes.
Were you invoking that template with There is a test that demonstrate it works, so if you are still having issues It would be best to provide reproduction steps (or even better script). |
@byroot yes I'm invoking that template with Steps to reproduceCreate few users inside a company. And in company <%# app/views/company/show.html.erb %>
<div id="users">
<%= render partial: "user", collection: @users %>
</div> Set a strict local in the _post partial: <%# app/views/company/_user.html.erb %>
<%# locals: (user:) %>
<div id="<%= dom_id user %>">
<p>
<strong>No.:</strong>
<%= user_counter %>
</p>
<p>
<strong>Name:</strong>
<%= user.name %>
</p>
</div> Expected behavior Actual behavior
If I remove magic comment in partial, this error goes away |
<%# locals: (user:) %> That's your bug, you must declare that argument: <%# locals: (user:, user_counter:) %> or <%# locals: (user:, user_counter: nil) %> |
I tried
the error become:
I updated to Rails 7.1.2. This is my Gemfile.lock Gemfile.lock
|
Ok, I found the bug, I'll prepare another fix. I need to figure out how our test didn't catch that one though. |
Fix: rails#49782 There was a bug in how we computed the list of required keys which wasn't caught by the test.
Fix: rails#49782 There was a bug in how we computed the list of required keys which wasn't caught by the test.
yep. Thank you. |
Ok, merged and backported. 7-1-stable should work for you now. |
Fix: #49780
Fix: #49761
CollectionRenderer
implictly inject<name>_counter
and<name>_iteration
locals, but in the overwhelming majority of cases they aren't used.So when the rendered template has strict locals we shouldn't require these to be declared, and if they aren't we should simply not pass them.
Co-Authored-By: @HolyWalley
@HolyWalley I hope you don't mind, I directly refactored your PR to save a bit of time. Most of it was good, but I had to change the parameters parsing a bit.