Skip to content

Commit 13ab57f

Browse files
committed
Support .visit(path, {except: 'prop') without only:
1 parent f35d898 commit 13ab57f

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

lib/inertia_rails/renderer.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def merge_props(shared_data, props)
7676
def computed_props
7777
_props = merge_props(shared_data, props).select do |key, prop|
7878
if rendering_partial_component?
79-
key.in?(partial_keys) || prop.is_a?(AlwaysProp)
79+
partial_keys.none? || key.in?(partial_keys) || prop.is_a?(AlwaysProp)
8080
else
8181
!prop.is_a?(LazyProp)
8282
end
@@ -130,7 +130,7 @@ def partial_except_keys
130130
end
131131

132132
def rendering_partial_component?
133-
@request.inertia_partial? && @request.headers['X-Inertia-Partial-Component'] == component
133+
@request.headers['X-Inertia-Partial-Component'] == component
134134
end
135135

136136
def resolve_component(component)

lib/patches/request.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ def inertia?
44
end
55

66
def inertia_partial?
7-
key? 'HTTP_X_INERTIA_PARTIAL_DATA'
7+
key?('HTTP_X_INERTIA_PARTIAL_COMPONENT')
88
end
99
end

spec/inertia/rendering_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,23 @@
132132
)
133133
end
134134

135+
context 'when except without X-Inertia-Partial-Data' do
136+
let(:headers) {{
137+
'X-Inertia' => true,
138+
'X-Inertia-Partial-Except' => 'nested',
139+
'X-Inertia-Partial-Component' => 'TestComponent',
140+
}}
141+
142+
it 'returns all regular and partial props except excepted' do
143+
expect(response.parsed_body['props']).to eq(
144+
'flat' => 'flat param',
145+
'lazy' => 'lazy param',
146+
'always' => 'always prop',
147+
'nested_lazy' => { 'first' => 'first nested lazy param' },
148+
)
149+
end
150+
end
151+
135152
context 'when except always prop' do
136153
let(:headers) {{
137154
'X-Inertia' => true,

spec/inertia/request_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
before { get inertia_partial_request_test_path, headers: headers }
2222

2323
context 'it is a partial inertia call' do
24-
let(:headers) { { 'X-Inertia' => true, 'X-Inertia-Partial-Data' => 'foo,bar,baz' } }
24+
let(:headers) { { 'X-Inertia' => true, 'X-Inertia-Partial-Component' => 'Component', 'X-Inertia-Partial-Data' => 'foo,bar,baz' } }
2525

2626
it { is_expected.to eq 202 }
2727
end

0 commit comments

Comments
 (0)