@@ -38,8 +38,6 @@ class Response implements Responsable
3838
3939 protected ?Closure $ urlResolver = null ;
4040
41- protected ?Closure $ oncePropsResolver = null ;
42-
4341 /**
4442 * @param array|Arrayable $props
4543 */
@@ -50,7 +48,6 @@ public function __construct(
5048 string $ version = '' ,
5149 bool $ encryptHistory = false ,
5250 ?Closure $ urlResolver = null ,
53- ?Closure $ oncePropsResolver = null ,
5451 ) {
5552 $ this ->component = $ component ;
5653 $ this ->props = $ props instanceof Arrayable ? $ props ->toArray () : $ props ;
@@ -59,7 +56,6 @@ public function __construct(
5956 $ this ->clearHistory = session ()->pull ('inertia.clear_history ' , false );
6057 $ this ->encryptHistory = $ encryptHistory ;
6158 $ this ->urlResolver = $ urlResolver ;
62- $ this ->oncePropsResolver = $ oncePropsResolver ;
6359 }
6460
6561 /**
@@ -130,14 +126,13 @@ public function toResponse($request)
130126 $ this ->resolveMergeProps ($ request ),
131127 $ this ->resolveDeferredProps ($ request ),
132128 $ this ->resolveCacheDirections ($ request ),
129+ $ this ->resolveOnceProps ($ request ),
133130 );
134131
135132 if ($ request ->header (Header::INERTIA )) {
136133 return new JsonResponse ($ page , 200 , [Header::INERTIA => 'true ' ]);
137134 }
138135
139- $ page += $ this ->resolveOnceProps ($ request );
140-
141136 return ResponseFactory::view ($ this ->rootView , $ this ->viewData + ['page ' => $ page ]);
142137 }
143138
@@ -150,6 +145,7 @@ public function resolveProperties(Request $request, array $props): array
150145 $ props = $ this ->resolveArrayableProperties ($ props , $ request );
151146 $ props = $ this ->resolveAlways ($ props );
152147 $ props = $ this ->resolvePropertyInstances ($ props , $ request );
148+ $ props = $ this ->removeOnceProperties ($ props );
153149
154150 return $ props ;
155151 }
@@ -302,6 +298,14 @@ public function resolvePropertyInstances(array $props, Request $request): array
302298 return $ props ;
303299 }
304300
301+ /**
302+ * Remove once properties from the response.
303+ */
304+ public function removeOnceProperties (array $ props ): array
305+ {
306+ return array_filter ($ props , static fn ($ prop ) => ! $ prop instanceof OnceProp);
307+ }
308+
305309 /**
306310 * Resolve the cache directions for the response.
307311 */
@@ -384,11 +388,15 @@ public function resolveDeferredProps(Request $request): array
384388
385389 public function resolveOnceProps (Request $ request ): array
386390 {
387- $ onceProps = $ this ->oncePropsResolver
388- ? App::call ($ this ->oncePropsResolver , ['request ' => $ request ])
389- : [];
391+ if ($ request ->header (Header::INERTIA )) {
392+ return [];
393+ }
394+
395+ $ onceProps = collect ($ this ->props )
396+ ->filter (fn ($ prop ) => $ prop instanceof OnceProp)
397+ ->mapWithKeys (fn ($ value , $ key ) => [$ key => App::call ($ value )]);
390398
391- return empty ( $ onceProps ) ? [] : [ 'onceProps ' => $ onceProps ];
399+ return $ onceProps-> isNotEmpty ( ) ? ['onceProps ' => $ onceProps-> toArray ()] : [ ];
392400 }
393401
394402 /**
0 commit comments