Skip to content

Commit d5f43e3

Browse files
committed
Deep merge props passed to render method with the shared data
1 parent bd658da commit d5f43e3

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

lib/inertia_rails/renderer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def layout
4242
end
4343

4444
def props
45-
_props = ::InertiaRails.shared_data(@controller).merge(@props).select do |key, prop|
45+
_props = ::InertiaRails.shared_data(@controller).deep_merge(@props).select do |key, prop|
4646
if rendering_partial_component?
4747
key.in? partial_keys
4848
else
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class InertiaMergeSharedController < ApplicationController
2+
inertia_share do
3+
{
4+
nested: {
5+
goals: 100,
6+
assists: 100,
7+
}
8+
}
9+
end
10+
11+
def merge_shared
12+
render inertia: 'ShareTestComponent', props: {
13+
nested: {
14+
assists: 200,
15+
}
16+
}
17+
end
18+
end

spec/dummy/config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,6 @@
3434
get 'provided_props_test' => 'inertia_rails_mimic#provided_props_test'
3535

3636
inertia 'inertia_route' => 'TestComponent'
37+
38+
get 'merge_shared' => 'inertia_merge_shared#merge_shared'
3739
end

spec/inertia/sharing_spec.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
RSpec.describe 'using inertia share when rendering views', type: :request do
2-
subject { JSON.parse(response.body)['props'].symbolize_keys }
2+
subject { JSON.parse(response.body)['props'].deep_symbolize_keys }
33

44
context 'using inertia share' do
55
let(:props) { {name: 'Brandon', sport: 'hockey', position: 'center', number: 29} }
@@ -99,4 +99,10 @@
9999
expect(InertiaRails.shared_blocks).to be_empty
100100
end
101101
end
102+
103+
describe 'deep merging with shared data' do
104+
let(:props) { { nested: { goals: 100, assists: 200 } } }
105+
before { get merge_shared_path, headers: {'X-Inertia' => true} }
106+
it { is_expected.to eq props }
107+
end
102108
end

0 commit comments

Comments
 (0)