diff --git a/src/Service/Inertia.php b/src/Service/Inertia.php index ae4bb50..ec25876 100644 --- a/src/Service/Inertia.php +++ b/src/Service/Inertia.php @@ -38,8 +38,8 @@ public function render(string $component, array $props = []): ResponseInterface ->withUrl((string)$this->request->getUri()); if ($this->request->hasHeader('X-Inertia-Partial-Data')) { - $only = $this->request->getHeader('X-Inertia-Partial-Data'); - $props = ($only && $this->request->getHeaderLine('X-Inertia-Partial-Component')) + $only = explode(',', $this->request->getHeaderLine('X-Inertia-Partial-Data')); + $props = ($only && $this->request->getHeaderLine('X-Inertia-Partial-Component') === $component) ? array_intersect_key($props, array_flip((array) $only)) : $props; } diff --git a/test/Service/InertiaTest.php b/test/Service/InertiaTest.php index b800c2c..ff7aa1d 100644 --- a/test/Service/InertiaTest.php +++ b/test/Service/InertiaTest.php @@ -98,11 +98,9 @@ public function testRenderReturnPartialDataWhenHeaderContainsPartialData() $request = $this->prophesize(ServerRequestInterface::class); $request->hasHeader('X-Inertia')->willReturn(true); $request->hasHeader('X-Inertia-Partial-Data')->willReturn(true); - $request->getHeaderLine('X-Inertia-Partial-Component')->willReturn(Argument::type('string')); - $request->getHeader('X-Inertia-Partial-Data')->willReturn([ - 'key2' - ]); - $json = '{"component":"type(string)","props":{"key2":"value2"},"url":"callback()","version":null}'; + $request->getHeaderLine('X-Inertia-Partial-Component')->willReturn('component'); + $request->getHeaderLine('X-Inertia-Partial-Data')->willReturn('key2'); + $json = '{"component":"component","props":{"key2":"value2"},"url":"callback()","version":null}'; $jsonResponse = null; $uri = $this->prophesize(UriInterface::class); @@ -133,7 +131,7 @@ public function testRenderReturnPartialDataWhenHeaderContainsPartialData() ); $returnedResponse = $inertia->render( - Argument::type('string'), + 'component', [ 'key1' => fn() => 'value1', 'key2' => fn() => 'value2'