File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -26,8 +26,11 @@ class Configuration
26
26
# Used to detect version drift between server and client.
27
27
version : nil ,
28
28
29
- # Allows configuring the base controller for StaticController
29
+ # Allows configuring the base controller for StaticController.
30
30
parent_controller : '::ApplicationController' ,
31
+
32
+ # Whether to include empty `errors` hash to the props when no errors are present.
33
+ always_include_errors_hash : nil ,
31
34
} . freeze
32
35
33
36
OPTION_NAMES = DEFAULTS . keys . freeze
Original file line number Diff line number Diff line change @@ -144,7 +144,22 @@ def inertia_configuration
144
144
end
145
145
146
146
def inertia_shared_data
147
- initial_data = session [ :inertia_errors ] . present? ? { errors : session [ :inertia_errors ] } : { }
147
+ initial_data =
148
+ if session [ :inertia_errors ] . present?
149
+ { errors : session [ :inertia_errors ] }
150
+ elsif inertia_configuration . always_include_errors_hash
151
+ { errors : { } }
152
+ else
153
+ if inertia_configuration . always_include_errors_hash . nil?
154
+ InertiaRails . deprecator . warn (
155
+ "To comply with the Inertia protocol, an empty errors hash `{errors: {}}` " \
156
+ "will be included to all responses by default starting with InertiaRails 4.0. " \
157
+ "To opt-in now, set `config.always_include_errors_hash = true`. " \
158
+ "To disable this warning, set it to `false`."
159
+ )
160
+ end
161
+ { }
162
+ end
148
163
149
164
self . class . _inertia_shared_data . filter_map { |shared_data |
150
165
if shared_data . respond_to? ( :call )
You can’t perform that action at this time.
0 commit comments