Skip to content

Commit dfa8425

Browse files
authored
Reintroduce inertia.ssr.enabled config option (#488)
1 parent d82548e commit dfa8425

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

config/inertia.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
'ssr' => [
2323

24+
'enabled' => true,
25+
2426
'url' => 'http://127.0.0.1:13714',
2527

2628
// 'bundle' => base_path('bootstrap/ssr/ssr.mjs'),

src/Commands/StartSsr.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ class StartSsr extends Command
2828
*/
2929
public function handle(): int
3030
{
31+
if (! config('inertia.ssr.enabled', true)) {
32+
$this->error('Inertia SSR is not enabled. Enable it via the `inertia.ssr.enabled` config option.');
33+
34+
return self::FAILURE;
35+
}
36+
3137
$bundle = (new BundleDetector())->detect();
3238
$configuredBundle = config('inertia.ssr.bundle');
3339

src/Ssr/HttpGateway.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class HttpGateway implements Gateway
1212
*/
1313
public function dispatch(array $page): ?Response
1414
{
15-
if (! (new BundleDetector())->detect()) {
15+
if (! config('inertia.ssr.enabled', true) || ! (new BundleDetector())->detect()) {
1616
return null;
1717
}
1818

tests/DirectiveTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ protected function renderView($contents, $data = [])
9292

9393
public function test_inertia_directive_renders_the_root_element(): void
9494
{
95+
Config::set(['inertia.ssr.enabled' => false]);
96+
9597
$html = '<div id="app" data-page="{&quot;component&quot;:&quot;Foo\/Bar&quot;,&quot;props&quot;:{&quot;foo&quot;:&quot;bar&quot;},&quot;url&quot;:&quot;\/test&quot;,&quot;version&quot;:&quot;&quot;}"></div>';
9698

9799
$this->assertSame($html, $this->renderView('@inertia', ['page' => self::EXAMPLE_PAGE_OBJECT]));
@@ -112,6 +114,8 @@ public function test_inertia_directive_renders_server_side_rendered_content_when
112114

113115
public function test_inertia_directive_can_use_a_different_root_element_id(): void
114116
{
117+
Config::set(['inertia.ssr.enabled' => false]);
118+
115119
$html = '<div id="foo" data-page="{&quot;component&quot;:&quot;Foo\/Bar&quot;,&quot;props&quot;:{&quot;foo&quot;:&quot;bar&quot;},&quot;url&quot;:&quot;\/test&quot;,&quot;version&quot;:&quot;&quot;}"></div>';
116120

117121
$this->assertSame($html, $this->renderView('@inertia(foo)', ['page' => self::EXAMPLE_PAGE_OBJECT]));
@@ -121,6 +125,8 @@ public function test_inertia_directive_can_use_a_different_root_element_id(): vo
121125

122126
public function test_inertia_head_directive_renders_nothing(): void
123127
{
128+
Config::set(['inertia.ssr.enabled' => false]);
129+
124130
$this->assertEmpty($this->renderView('@inertiaHead', ['page' => self::EXAMPLE_PAGE_OBJECT]));
125131
}
126132

0 commit comments

Comments
 (0)