Skip to content

Commit c07625d

Browse files
authored
Fix bug where SSR is dispatched twice when errors exist (#489)
1 parent dfa8425 commit c07625d

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/Directive.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ public static function compile($expression = ''): string
1414
$id = trim(trim($expression), "\'\"") ?: 'app';
1515

1616
$template = '<?php
17-
if (!isset($__inertiaSsr)) {
18-
$__inertiaSsr = app(\Inertia\Ssr\Gateway::class)->dispatch($page);
17+
if (!isset($__inertiaSsrDispatched)) {
18+
$__inertiaSsrDispatched = true;
19+
$__inertiaSsrResponse = app(\Inertia\Ssr\Gateway::class)->dispatch($page);
1920
}
2021
21-
if ($__inertiaSsr instanceof \Inertia\Ssr\Response) {
22-
echo $__inertiaSsr->body;
22+
if ($__inertiaSsrResponse) {
23+
echo $__inertiaSsrResponse->body;
2324
} else {
2425
?><div id="'.$id.'" data-page="{{ json_encode($page) }}"></div><?php
2526
}
@@ -36,12 +37,13 @@ public static function compile($expression = ''): string
3637
public static function compileHead($expression = ''): string
3738
{
3839
$template = '<?php
39-
if (!isset($__inertiaSsr)) {
40-
$__inertiaSsr = app(\Inertia\Ssr\Gateway::class)->dispatch($page);
40+
if (!isset($__inertiaSsrDispatched)) {
41+
$__inertiaSsrDispatched = true;
42+
$__inertiaSsrResponse = app(\Inertia\Ssr\Gateway::class)->dispatch($page);
4143
}
4244
43-
if ($__inertiaSsr instanceof \Inertia\Ssr\Response) {
44-
echo $__inertiaSsr->head;
45+
if ($__inertiaSsrResponse) {
46+
echo $__inertiaSsrResponse->head;
4547
}
4648
?>';
4749

0 commit comments

Comments
 (0)