Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/Events/LivewireDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public function register(): void
}

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

if (! $handled->response->isSuccessful()) {
return;
Expand Down Expand Up @@ -50,7 +50,13 @@ public function handle(RequestHandled $handled)
HTML)
);

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

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