@@ -38,8 +38,6 @@ class Response implements Responsable
38
38
39
39
protected ?Closure $ urlResolver = null ;
40
40
41
- protected ?Closure $ oncePropsResolver = null ;
42
-
43
41
/**
44
42
* @param array|Arrayable $props
45
43
*/
@@ -50,7 +48,6 @@ public function __construct(
50
48
string $ version = '' ,
51
49
bool $ encryptHistory = false ,
52
50
?Closure $ urlResolver = null ,
53
- ?Closure $ oncePropsResolver = null ,
54
51
) {
55
52
$ this ->component = $ component ;
56
53
$ this ->props = $ props instanceof Arrayable ? $ props ->toArray () : $ props ;
@@ -59,7 +56,6 @@ public function __construct(
59
56
$ this ->clearHistory = session ()->pull ('inertia.clear_history ' , false );
60
57
$ this ->encryptHistory = $ encryptHistory ;
61
58
$ this ->urlResolver = $ urlResolver ;
62
- $ this ->oncePropsResolver = $ oncePropsResolver ;
63
59
}
64
60
65
61
/**
@@ -130,14 +126,13 @@ public function toResponse($request)
130
126
$ this ->resolveMergeProps ($ request ),
131
127
$ this ->resolveDeferredProps ($ request ),
132
128
$ this ->resolveCacheDirections ($ request ),
129
+ $ this ->resolveInitialProps ($ request ),
133
130
);
134
131
135
132
if ($ request ->header (Header::INERTIA )) {
136
133
return new JsonResponse ($ page , 200 , [Header::INERTIA => 'true ' ]);
137
134
}
138
135
139
- $ page += $ this ->resolveOnceProps ($ request );
140
-
141
136
return ResponseFactory::view ($ this ->rootView , $ this ->viewData + ['page ' => $ page ]);
142
137
}
143
138
@@ -150,6 +145,7 @@ public function resolveProperties(Request $request, array $props): array
150
145
$ props = $ this ->resolveArrayableProperties ($ props , $ request );
151
146
$ props = $ this ->resolveAlways ($ props );
152
147
$ props = $ this ->resolvePropertyInstances ($ props , $ request );
148
+ $ props = $ this ->removeInitialProperties ($ props );
153
149
154
150
return $ props ;
155
151
}
@@ -302,6 +298,14 @@ public function resolvePropertyInstances(array $props, Request $request): array
302
298
return $ props ;
303
299
}
304
300
301
+ /**
302
+ * Remove initial properties from the response.
303
+ */
304
+ public function removeInitialProperties (array $ props ): array
305
+ {
306
+ return array_filter ($ props , static fn ($ prop ) => ! $ prop instanceof InitialProp);
307
+ }
308
+
305
309
/**
306
310
* Resolve the cache directions for the response.
307
311
*/
@@ -382,13 +386,17 @@ public function resolveDeferredProps(Request $request): array
382
386
return $ deferredProps ->isNotEmpty () ? ['deferredProps ' => $ deferredProps ->toArray ()] : [];
383
387
}
384
388
385
- public function resolveOnceProps (Request $ request ): array
389
+ public function resolveInitialProps (Request $ request ): array
386
390
{
387
- $ onceProps = $ this ->oncePropsResolver
388
- ? App::call ($ this ->oncePropsResolver , ['request ' => $ request ])
389
- : [];
391
+ if ($ request ->header (Header::INERTIA )) {
392
+ return [];
393
+ }
394
+
395
+ $ initialProps = collect ($ this ->props )
396
+ ->filter (fn ($ prop ) => $ prop instanceof InitialProp)
397
+ ->mapWithKeys (fn ($ value , $ key ) => [$ key => App::call ($ value )]);
390
398
391
- return empty ( $ onceProps ) ? [] : [ ' onceProps ' => $ onceProps ];
399
+ return $ initialProps -> isNotEmpty ( ) ? [' initialProps ' => $ initialProps -> toArray ()] : [ ];
392
400
}
393
401
394
402
/**
0 commit comments