Skip to content

Commit a7f87fd

Browse files
committed
Always keep errors in the props
1 parent 09cabb6 commit a7f87fd

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/inertia_rails/renderer.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ def merge_props(shared_props, props)
9191

9292
def computed_props
9393
merged_props = merge_props(shared_data, props)
94+
# Always keep errors in the props
95+
if merged_props.key?(:errors) && !merged_props[:errors].is_a?(BaseProp)
96+
errors = merged_props[:errors]
97+
merged_props[:errors] = InertiaRails.always { errors }
98+
end
9499
deep_transform_props(merged_props).tap do |transformed_props|
95100
transformed_props[:_inertia_meta] = meta_tags if meta_tags.present?
96101
end

spec/inertia/error_sharing_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,27 @@
4545
expect(response.body).to include(CGI::escape_html({ errors: { uh: 'oh' } }.to_json))
4646
expect(session[:inertia_errors]).not_to be
4747
end
48+
49+
context 'with partial update' do
50+
let(:headers) do
51+
{
52+
'X-Inertia' => true,
53+
'X-Inertia-Version' => server_version,
54+
'X-Inertia-Partial-Component' => 'EmptyTestComponent',
55+
'X-Inertia-Partial-Data' => 'foo',
56+
}
57+
end
58+
59+
it 'keeps errors when partial inertia request redirects' do
60+
post redirect_with_inertia_errors_path, headers: headers
61+
expect(response.headers['Location']).to eq(empty_test_url)
62+
expect(session[:inertia_errors]).to include({ uh: 'oh' })
63+
64+
# Follow the redirect
65+
get response.headers['Location'], headers: headers
66+
expect(response.body).to include({ errors: { uh: 'oh' } }.to_json)
67+
expect(session[:inertia_errors]).not_to be
68+
end
69+
end
4870
end
4971
end

0 commit comments

Comments
 (0)