Skip to content

Commit ce859b2

Browse files
committed
perf: reduce array allocations when controllers don't override shared data
1 parent 05b211d commit ce859b2

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/inertia_rails/controller.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,20 @@ def use_inertia_instance_props
4040
def _inertia_configuration
4141
@_inertia_configuration ||= begin
4242
config = superclass.try(:_inertia_configuration) || ::InertiaRails.configuration
43-
@inertia_config ? config.merge(@inertia_config).freeze : config
43+
@inertia_config ? config.merge(@inertia_config.freeze).freeze : config
4444
end
4545
end
4646

4747
def _inertia_shared_data
48-
@_inertia_shared_data ||= [*superclass.try(:_inertia_shared_data), *@inertia_share].freeze
48+
@_inertia_shared_data ||= begin
49+
shared_data = superclass.try(:_inertia_shared_data)
50+
51+
if @inertia_share && shared_data.present?
52+
shared_data + @inertia_share.freeze
53+
else
54+
@inertia_share || shared_data || []
55+
end.freeze
56+
end
4957
end
5058
end
5159

0 commit comments

Comments
 (0)