Skip to content

Commit

Permalink
Fix Locals need to be shallow cloned. (#22)
Browse files Browse the repository at this point in the history
Resolves #20. `prop_template` prebuilds an array of options before
handling it off to handle_collection to build. I recall this being
somewhat related to faster collection rendering. Unfortunately,
the trade off is that we have to be cognizant of how we mutate deeply
nested options as those can be the same object. In this case, I missed
a required clone on locals.
  • Loading branch information
jho406 authored Jul 20, 2024
1 parent 1e91b17 commit 890bffb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/props_template/extensions/partial_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def refine_options(options, item = nil)

partial, rest = [*options[:partial]]
rest = (rest || {}).clone
locals = rest[:locals] || {}
locals = (rest[:locals] || {}).clone
rest[:locals] = locals

if item
Expand Down
4 changes: 1 addition & 3 deletions spec/extensions/partial_render_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@
])
end

it "renders an array with :locals" do
it "renders an array with default :locals when locals is blank" do
json = render(<<~PROPS)
emails = [
{value: '[email protected]'},
Expand All @@ -309,8 +309,6 @@
end
PROPS

puts json.inspect

expect(json).to eql_json([
{foo: "[email protected]"},
{foo: "[email protected]"}
Expand Down

0 comments on commit 890bffb

Please sign in to comment.