Skip to content

Commit 4c5793c

Browse files
authored
Merge pull request #18 from jsandfordhughescoop/fix-livewire-dispatch
fix: adds check for original content existence
2 parents b73bf02 + 84a4340 commit 4c5793c

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/Events/LivewireDispatcher.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ public function register(): void
1616
}
1717

1818
/** Injects assets inside every full-page response */
19-
public function handle(RequestHandled $handled)
19+
public function handle(RequestHandled $handled): void
2020
{
2121
$identifier = 'NativePHP Livewire Dispatcher';
2222
$html = $handled->response->getContent();
23-
$originalContent = $handled->response->original;
23+
$originalContent = $handled->response->original ?? null;
2424

2525
if (! $handled->response->isSuccessful()) {
2626
return;
@@ -50,7 +50,13 @@ public function handle(RequestHandled $handled)
5050
HTML)
5151
);
5252

53-
$handled->response->original = $originalContent;
53+
// Laravel dispatches the ResponseHandled event even for response
54+
// objects that don't include the `original` property.
55+
// The typehint in Laravel core is wrong, so we ignore
56+
/* @phpstan-ignore function.alreadyNarrowedType */
57+
if (property_exists($handled->response, 'original')) {
58+
$handled->response->original = $originalContent;
59+
}
5460
}
5561

5662
/** Injects assets into given html string (taken from Livewire's injection mechanism) */

0 commit comments

Comments
 (0)