Skip to content

Commit 75dd79c

Browse files
committed
Add DisablesSsr interface
1 parent 0d8b618 commit 75dd79c

4 files changed

Lines changed: 22 additions & 8 deletions

File tree

src/ResponseFactory.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Illuminate\Support\Facades\Request;
1717
use Illuminate\Support\Facades\Response as BaseResponse;
1818
use Illuminate\Support\Traits\Macroable;
19+
use Inertia\Ssr\DisablesSsr;
1920
use Inertia\Ssr\ExcludesSsrPaths;
2021
use Inertia\Ssr\Gateway;
2122
use Inertia\Support\Header;
@@ -193,11 +194,11 @@ public function disableSsr(Closure|bool $condition = true): void
193194
{
194195
$gateway = app(Gateway::class);
195196

196-
if (! $gateway instanceof Ssr\HttpGateway) {
197-
throw new LogicException('The configured SSR gateway does not support conditionally disabling server-side rendering.');
197+
if (! $gateway instanceof DisablesSsr) {
198+
throw new LogicException('The configured SSR gateway does not support disabling server-side rendering conditionally.');
198199
}
199200

200-
$gateway->disableWhen($condition);
201+
$gateway->disable($condition);
201202
}
202203

203204
/**

src/Ssr/DisablesSsr.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Inertia\Ssr;
4+
5+
use Closure;
6+
7+
interface DisablesSsr
8+
{
9+
/**
10+
* Set the condition that determines if SSR should be disabled.
11+
*/
12+
public function disable(Closure|bool $condition): void;
13+
}

src/Ssr/HttpGateway.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Illuminate\Support\Str;
1414
use Inertia\ResolvesCallables;
1515

16-
class HttpGateway implements ExcludesSsrPaths, Gateway, HasHealthCheck
16+
class HttpGateway implements DisablesSsr, ExcludesSsrPaths, Gateway, HasHealthCheck
1717
{
1818
use ExcludesPaths;
1919
use ResolvesCallables;
@@ -85,7 +85,7 @@ public function dispatch(array $page, ?Request $request = null): ?Response
8585
/**
8686
* Set the condition that determines if SSR should be disabled.
8787
*/
88-
public function disableWhen(Closure|bool $condition): void
88+
public function disable(Closure|bool $condition): void
8989
{
9090
$this->disabled = $condition;
9191
}

tests/HttpGatewayTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ public function test_it_returns_null_when_disabled_with_boolean(): void
438438
'inertia.ssr.bundle' => __DIR__.'/Stubs/ssr-bundle.js',
439439
]);
440440

441-
$this->gateway->disableWhen(true);
441+
$this->gateway->disable(true);
442442

443443
$this->assertNull($this->gateway->dispatch(['page' => self::EXAMPLE_PAGE_OBJECT]));
444444
}
@@ -450,7 +450,7 @@ public function test_it_returns_null_when_disabled_with_closure(): void
450450
'inertia.ssr.bundle' => __DIR__.'/Stubs/ssr-bundle.js',
451451
]);
452452

453-
$this->gateway->disableWhen(fn () => true);
453+
$this->gateway->disable(fn () => true);
454454

455455
$this->assertNull($this->gateway->dispatch(['page' => self::EXAMPLE_PAGE_OBJECT]));
456456
}
@@ -462,7 +462,7 @@ public function test_disable_when_takes_precedence_over_config(): void
462462
'inertia.ssr.bundle' => __DIR__.'/Stubs/ssr-bundle.js',
463463
]);
464464

465-
$this->gateway->disableWhen(false);
465+
$this->gateway->disable(false);
466466

467467
Http::fake([
468468
$this->renderUrl => Http::response(json_encode([

0 commit comments

Comments
 (0)