Skip to content

Commit

Permalink
Merge pull request #692 from crynobone/v1-spec
Browse files Browse the repository at this point in the history
[1.x] Ensure Inertia Response generate also compatible with Inertia.js 2
  • Loading branch information
joetannenbaum authored Dec 5, 2024
2 parents 9ab470d + bc897f8 commit c30424e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public function toResponse($request)
'props' => $props,
'url' => Str::start(Str::after($request->fullUrl(), $request->getSchemeAndHttpHost()), '/'),
'version' => $this->version,
'encryptHistory' => false,
'clearHistory' => false,
];

if ($request->header(Header::INERTIA)) {
Expand Down
2 changes: 2 additions & 0 deletions tests/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public function test_controller_returns_an_inertia_response(): void
],
'url' => '/',
'version' => '',
'encryptHistory' => false,
'clearHistory' => false,
]);
}
}
5 changes: 2 additions & 3 deletions tests/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function test_server_response(): void
$this->assertSame('Jonathan', $page['props']['user']['name']);
$this->assertSame('/user/123', $page['url']);
$this->assertSame('123', $page['version']);
$this->assertSame('<div id="app" data-page="{&quot;component&quot;:&quot;User\/Edit&quot;,&quot;props&quot;:{&quot;user&quot;:{&quot;name&quot;:&quot;Jonathan&quot;}},&quot;url&quot;:&quot;\/user\/123&quot;,&quot;version&quot;:&quot;123&quot;}"></div>', $view->render());
$this->assertSame('<div id="app" data-page="{&quot;component&quot;:&quot;User\/Edit&quot;,&quot;props&quot;:{&quot;user&quot;:{&quot;name&quot;:&quot;Jonathan&quot;}},&quot;url&quot;:&quot;\/user\/123&quot;,&quot;version&quot;:&quot;123&quot;,&quot;encryptHistory&quot;:false,&quot;clearHistory&quot;:false}"></div>', $view->render());
}

public function test_xhr_response(): void
Expand Down Expand Up @@ -98,8 +98,7 @@ public function test_lazy_resource_response(): void
$callable = static function () use ($users) {
$page = new LengthAwarePaginator($users->take(2), $users->count(), 2);

return new class($page, JsonResource::class) extends ResourceCollection {
};
return new class($page, JsonResource::class) extends ResourceCollection {};
};

$response = new Response('User/Index', ['users' => $callable], 'app', '123');
Expand Down

0 comments on commit c30424e

Please sign in to comment.