Skip to content

Commit 776da3a

Browse files
committed
Don't filter out intentionally empty hashes from transformed props
1 parent af8fb91 commit 776da3a

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

lib/inertia_rails/renderer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def deep_transform_props(props, parent_path = [], &block)
105105
props.reduce({}) do |transformed_props, (key, prop)|
106106
current_path = parent_path + [key]
107107

108-
if prop.is_a?(Hash)
108+
if prop.is_a?(Hash) && prop.any?
109109
nested = deep_transform_props(prop, current_path, &block)
110110
transformed_props.merge!(key => nested) unless nested.empty?
111111
else

spec/dummy/app/controllers/inertia_render_test_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def deeply_nested_props
4040
first: 'first deeply nested param',
4141
second: false,
4242
what_about_nil: nil,
43+
what_about_empty_hash: {},
4344
deeply_nested_always: InertiaRails.always { 'deeply nested always prop' },
4445
deeply_nested_lazy: InertiaRails.lazy { 'deeply nested lazy prop' }
4546
}

spec/inertia/rendering_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
let(:headers) do
117117
{
118118
'X-Inertia' => true,
119-
'X-Inertia-Partial-Data' => 'nested.first,nested.deeply_nested.second,nested.deeply_nested.what_about_nil',
119+
'X-Inertia-Partial-Data' => 'nested.first,nested.deeply_nested.second,nested.deeply_nested.what_about_nil,nested.deeply_nested.what_about_empty_hash',
120120
'X-Inertia-Partial-Component' => 'TestComponent',
121121
}
122122
end
@@ -131,6 +131,7 @@
131131
'deeply_nested' => {
132132
'second' => false,
133133
'what_about_nil' => nil,
134+
'what_about_empty_hash' => {},
134135
'deeply_nested_always' => 'deeply nested always prop',
135136
},
136137
},

0 commit comments

Comments
 (0)