File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,9 @@ class Configuration
12
12
# Allows the user to hook into the default rendering behavior and change it to fit their needs
13
13
component_path_resolver : -> ( path :, action :) { "#{ path } /#{ action } " } ,
14
14
15
+ # A function that transforms the props before they are sent to the client.
16
+ prop_transformer : -> ( props :) { props } ,
17
+
15
18
# DEPRECATED: Let Rails decide which layout should be used based on the
16
19
# controller configuration.
17
20
layout : true ,
@@ -89,6 +92,10 @@ def component_path_resolver(path:, action:)
89
92
@options [ :component_path_resolver ] . call ( path : path , action : action )
90
93
end
91
94
95
+ def prop_transformer ( props :)
96
+ @options [ :prop_transformer ] . call ( props : props )
97
+ end
98
+
92
99
OPTION_NAMES . each do |option |
93
100
unless method_defined? ( option )
94
101
define_method ( option ) do
Original file line number Diff line number Diff line change @@ -90,10 +90,13 @@ def merge_props(shared_props, props)
90
90
end
91
91
92
92
def computed_props
93
- merged_props = merge_props ( shared_data , props )
94
- deep_transform_props ( merged_props ) . tap do |transformed_props |
95
- transformed_props [ :_inertia_meta ] = meta_tags if meta_tags . present?
96
- end
93
+ merge_props ( shared_data , props )
94
+ # This performs the internal work of hydrating/filtering props
95
+ . then { |props | deep_transform_props ( props ) }
96
+ # Then we apply the user-defined prop transformer
97
+ . then { |props | configuration . prop_transformer ( props : props ) }
98
+ # Then we add meta tags after everything since they must not be transformed
99
+ . tap { |props | props [ :_inertia_meta ] = meta_tags if meta_tags . present? }
97
100
end
98
101
99
102
def page
You can’t perform that action at this time.
0 commit comments