Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.x] Ensure Inertia Response generate also compatible with Inertia.js 2 #692

Merged
merged 4 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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