From 3eb6b1e4c924d9f3ce50235f9cd2132774e3ba8d Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Thu, 28 Nov 2024 14:20:20 +0800 Subject: [PATCH 1/4] [1.x] Ensure Inertia Response generate also compatible with Inertia.js 2 This would allow application to uses multiple packages that use both Inertia.js 1 and 2 rely can `inertia/inertia-laravel` v1 before fully migrating to v2. Signed-off-by: Mior Muhammad Zaki --- src/Response.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Response.php b/src/Response.php index d2565294..643830e9 100644 --- a/src/Response.php +++ b/src/Response.php @@ -95,6 +95,7 @@ public function toResponse($request) 'props' => $props, 'url' => Str::start(Str::after($request->fullUrl(), $request->getSchemeAndHttpHost()), '/'), 'version' => $this->version, + 'encodeHistory' => false, ]; if ($request->header(Header::INERTIA)) { From 03de5dcf8f18b7b7093ff9c978d0e869278ca096 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Thu, 28 Nov 2024 15:11:22 +0800 Subject: [PATCH 2/4] wip Signed-off-by: Mior Muhammad Zaki --- tests/ControllerTest.php | 1 + tests/ResponseTest.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/ControllerTest.php b/tests/ControllerTest.php index 5e90f3e1..fc5d744c 100644 --- a/tests/ControllerTest.php +++ b/tests/ControllerTest.php @@ -28,6 +28,7 @@ public function test_controller_returns_an_inertia_response(): void ], 'url' => '/', 'version' => '', + 'encodeHistory' => false, ]); } } diff --git a/tests/ResponseTest.php b/tests/ResponseTest.php index ef692c02..c2bf3dc0 100644 --- a/tests/ResponseTest.php +++ b/tests/ResponseTest.php @@ -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('
', $view->render()); + $this->assertSame('
', $view->render()); } public function test_xhr_response(): void From d783ca216811561fc82b73fa49ef8103b3c41671 Mon Sep 17 00:00:00 2001 From: Joe Tannenbaum Date: Thu, 5 Dec 2024 09:28:17 -0500 Subject: [PATCH 3/4] encodeHistory -> encryptHistory --- src/Response.php | 2 +- tests/ControllerTest.php | 2 +- tests/ResponseTest.php | 5 ++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Response.php b/src/Response.php index 643830e9..01cec6fa 100644 --- a/src/Response.php +++ b/src/Response.php @@ -95,7 +95,7 @@ public function toResponse($request) 'props' => $props, 'url' => Str::start(Str::after($request->fullUrl(), $request->getSchemeAndHttpHost()), '/'), 'version' => $this->version, - 'encodeHistory' => false, + 'encryptHistory' => false, ]; if ($request->header(Header::INERTIA)) { diff --git a/tests/ControllerTest.php b/tests/ControllerTest.php index fc5d744c..e9841b78 100644 --- a/tests/ControllerTest.php +++ b/tests/ControllerTest.php @@ -28,7 +28,7 @@ public function test_controller_returns_an_inertia_response(): void ], 'url' => '/', 'version' => '', - 'encodeHistory' => false, + 'encryptHistory' => false, ]); } } diff --git a/tests/ResponseTest.php b/tests/ResponseTest.php index c2bf3dc0..764bdfda 100644 --- a/tests/ResponseTest.php +++ b/tests/ResponseTest.php @@ -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('
', $view->render()); + $this->assertSame('
', $view->render()); } public function test_xhr_response(): void @@ -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'); From bc897f8509c03276ba159ca020b0c9f1de29b381 Mon Sep 17 00:00:00 2001 From: Joe Tannenbaum Date: Thu, 5 Dec 2024 09:31:39 -0500 Subject: [PATCH 4/4] add clear history property --- src/Response.php | 1 + tests/ControllerTest.php | 1 + tests/ResponseTest.php | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Response.php b/src/Response.php index 01cec6fa..988cdbc8 100644 --- a/src/Response.php +++ b/src/Response.php @@ -96,6 +96,7 @@ public function toResponse($request) 'url' => Str::start(Str::after($request->fullUrl(), $request->getSchemeAndHttpHost()), '/'), 'version' => $this->version, 'encryptHistory' => false, + 'clearHistory' => false, ]; if ($request->header(Header::INERTIA)) { diff --git a/tests/ControllerTest.php b/tests/ControllerTest.php index e9841b78..42f60a43 100644 --- a/tests/ControllerTest.php +++ b/tests/ControllerTest.php @@ -29,6 +29,7 @@ public function test_controller_returns_an_inertia_response(): void 'url' => '/', 'version' => '', 'encryptHistory' => false, + 'clearHistory' => false, ]); } } diff --git a/tests/ResponseTest.php b/tests/ResponseTest.php index 764bdfda..4676d358 100644 --- a/tests/ResponseTest.php +++ b/tests/ResponseTest.php @@ -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('
', $view->render()); + $this->assertSame('
', $view->render()); } public function test_xhr_response(): void