@@ -27,19 +27,20 @@ public Response(string component, object props, string rootView, string? version
2727 public async Task ExecuteResultAsync ( ActionContext context )
2828 {
2929 SetContext ( context ) ;
30- ProcessResponse ( ) ;
30+ await ProcessResponse ( ) ;
3131
3232 await GetResult ( ) . ExecuteResultAsync ( _context ! ) ;
3333 }
3434
35- protected internal void ProcessResponse ( )
35+ protected internal async Task ProcessResponse ( )
3636 {
3737 var page = new Page
3838 {
3939 Component = _component ,
4040 Version = _version ,
4141 Url = _context ! . RequestedUri ( ) ,
42- Props = ResolveProperties ( _props . GetType ( ) . GetProperties ( ) . ToDictionary ( o => o . Name . ToCamelCase ( ) , o => o . GetValue ( _props ) ) )
42+ Props = await ResolveProperties ( _props . GetType ( ) . GetProperties ( )
43+ . ToDictionary ( o => o . Name . ToCamelCase ( ) , o => o . GetValue ( _props ) ) )
4344 } ;
4445
4546 var shared = _context ! . HttpContext . Features . Get < InertiaSharedData > ( ) ;
@@ -51,15 +52,15 @@ protected internal void ProcessResponse()
5152 SetPage ( page ) ;
5253 }
5354
54- private static Dictionary < string , object ? > PrepareProps ( Dictionary < string , object ? > props )
55+ private static async Task < Dictionary < string , object ? > > PrepareProps ( Dictionary < string , object ? > props )
5556 {
56- return props . ToDictionary ( pair => pair . Key , pair => pair . Value switch
57+ return ( await Task . WhenAll ( props . Select ( async pair => pair . Value switch
5758 {
58- Func < object ? > f => f . Invoke ( ) ,
59- LazyProp l => l . Invoke ( ) ,
60- AlwaysProp l => l . Invoke ( ) ,
61- _ => pair . Value
62- } ) ;
59+ Func < object ? > f => ( pair . Key , f . Invoke ( ) ) ,
60+ LazyProp l => ( pair . Key , await l . Invoke ( ) ) ,
61+ AlwaysProp l => ( pair . Key , await l . Invoke ( ) ) ,
62+ _ => ( pair . Key , pair . Value )
63+ } ) ) ) . ToDictionary ( pair => pair . Key , pair => pair . Item2 ) ;
6364 }
6465
6566 protected internal JsonResult GetJson ( )
@@ -111,7 +112,7 @@ public Response WithViewData(IDictionary<string, object> viewData)
111112 return this ;
112113 }
113114
114- private Dictionary < string , object ? > ResolveProperties ( Dictionary < string , object ? > props )
115+ private async Task < Dictionary < string , object ? > > ResolveProperties ( Dictionary < string , object ? > props )
115116 {
116117 var isPartial = _context ! . IsInertiaPartialComponent ( _component ) ;
117118
@@ -126,37 +127,29 @@ public Response WithViewData(IDictionary<string, object> viewData)
126127 props = props . ToDictionary ( kv => kv . Key , kv => kv . Value ) ;
127128
128129 if ( _context ! . HttpContext . Request . Headers . ContainsKey ( InertiaHeader . PartialOnly ) )
129- {
130130 props = ResolveOnly ( props ) ;
131- }
132131
133132 if ( _context ! . HttpContext . Request . Headers . ContainsKey ( InertiaHeader . PartialExcept ) )
134- {
135133 props = ResolveExcept ( props ) ;
136- }
137134 }
138135
139136 props = ResolveAlways ( props ) ;
140- props = PrepareProps ( props ) ;
137+ props = await PrepareProps ( props ) ;
141138
142139 return props ;
143140 }
144141
145142 private Dictionary < string , object ? > ResolveOnly ( Dictionary < string , object ? > props )
146- {
147- return _context ! . OnlyProps ( props ) ;
148- }
143+ => _context ! . OnlyProps ( props ) ;
149144
150145 private Dictionary < string , object ? > ResolveExcept ( Dictionary < string , object ? > props )
151- {
152- return _context ! . ExceptProps ( props ) ;
153- }
146+ => _context ! . ExceptProps ( props ) ;
154147
155148 private Dictionary < string , object ? > ResolveAlways ( Dictionary < string , object ? > props )
156149 {
157150 var alwaysProps = _props . GetType ( ) . GetProperties ( )
158- . Where ( o => o . PropertyType == typeof ( AlwaysProp ) )
159- . ToDictionary ( o => o . Name . ToCamelCase ( ) , o => o . GetValue ( _props ) ) ;
151+ . Where ( o => o . PropertyType == typeof ( AlwaysProp ) )
152+ . ToDictionary ( o => o . Name . ToCamelCase ( ) , o => o . GetValue ( _props ) ) ;
160153
161154 return props
162155 . Where ( kv => kv . Value is not AlwaysProp )
0 commit comments