From cb00da1d25f749bb6af71a9df5c17d3faaea66cc Mon Sep 17 00:00:00 2001 From: Joe Sandford-Hughes Date: Fri, 17 Oct 2025 12:52:28 +0100 Subject: [PATCH 1/3] fix: adds check for original content existance --- src/Events/LivewireDispatcher.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Events/LivewireDispatcher.php b/src/Events/LivewireDispatcher.php index fd3bea4..7c2d66e 100644 --- a/src/Events/LivewireDispatcher.php +++ b/src/Events/LivewireDispatcher.php @@ -20,7 +20,11 @@ public function handle(RequestHandled $handled) { $identifier = 'NativePHP Livewire Dispatcher'; $html = $handled->response->getContent(); - $originalContent = $handled->response->original; + $originalContent = $handled->response->original ?? null; + + if (! $originalContent) { + return; + } if (! $handled->response->isSuccessful()) { return; From 44414e4b2523f599e27f6ce23ea0773a82350d2c Mon Sep 17 00:00:00 2001 From: Joe Sandford-Hughes Date: Tue, 21 Oct 2025 07:45:04 +0100 Subject: [PATCH 2/3] feat: refactor to remove early return --- src/Events/LivewireDispatcher.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Events/LivewireDispatcher.php b/src/Events/LivewireDispatcher.php index 7c2d66e..2521d18 100644 --- a/src/Events/LivewireDispatcher.php +++ b/src/Events/LivewireDispatcher.php @@ -16,16 +16,12 @@ 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 ?? null; - if (! $originalContent) { - return; - } - if (! $handled->response->isSuccessful()) { return; } @@ -54,7 +50,9 @@ public function handle(RequestHandled $handled) HTML) ); - $handled->response->original = $originalContent; + if (property_exists($handled->response, 'original')) { + $handled->response->original = $originalContent; + } } /** Injects assets into given html string (taken from Livewire's injection mechanism) */ From 84a43402d968df076f8c9d4132167635ade5cbbe Mon Sep 17 00:00:00 2001 From: gwleuverink Date: Tue, 21 Oct 2025 11:06:44 +0200 Subject: [PATCH 3/3] add phpstan-ignore --- src/Events/LivewireDispatcher.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Events/LivewireDispatcher.php b/src/Events/LivewireDispatcher.php index 2521d18..d677727 100644 --- a/src/Events/LivewireDispatcher.php +++ b/src/Events/LivewireDispatcher.php @@ -50,6 +50,10 @@ public function handle(RequestHandled $handled): void HTML) ); + // 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; }