From 8a3f90fc3dd852a068ba65f529ed9ed7e3c3be17 Mon Sep 17 00:00:00 2001 From: HolgerHatGarKeineNode <123783602+HolgerHatGarKeineNode@users.noreply.github.com> Date: Wed, 20 May 2026 00:31:02 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20**Handle=20stale=20Livewire=20as?= =?UTF-8?q?set=20exceptions=20gracefully**=20-=20=E2=9C=85=20Added=20detec?= =?UTF-8?q?tion=20logic=20for=20stale=20Livewire=20asset=20patterns=20to?= =?UTF-8?q?=20avoid=20500=20errors.=20-=20=F0=9F=9B=A0=EF=B8=8F=20Updated?= =?UTF-8?q?=20exception=20handling=20to=20return=20404=20for=20stale=20ass?= =?UTF-8?q?et=20requests.=20-=20=F0=9F=94=87=20Prevented=20logging=20of=20?= =?UTF-8?q?stale=20asset=20exceptions=20to=20avoid=20unnecessary=20noise.?= =?UTF-8?q?=20-=20=E2=9C=85=20Added=20tests=20to=20verify=20404=20response?= =?UTF-8?q?s=20and=20absence=20of=20log=20entries=20for=20stale=20asset=20?= =?UTF-8?q?scenarios.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bootstrap/app.php | 28 +++++++++++++++++++----- tests/Feature/LivewireStaleAssetTest.php | 14 ++++++++++++ 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/bootstrap/app.php b/bootstrap/app.php index c7d97bf..af4aed4 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -25,12 +25,14 @@ return Application::configure(basePath: dirname(__DIR__)) ]); }) ->withExceptions(function (Exceptions $exceptions) { - $exceptions->render(function (Throwable $e, Request $request) { - if (! preg_match('#^livewire-[a-f0-9]+/(?:css|js)/#', $request->path())) { - return null; + $isStaleLivewireAsset = function (Throwable $e, ?Request $request): bool { + if (! $request instanceof Request) { + return false; } - $message = $e->getMessage(); + if (! preg_match('#^livewire-[a-f0-9]+/(?:css|js)/#', $request->path())) { + return false; + } $stalePatterns = [ 'does not have a style source', @@ -42,11 +44,25 @@ return Application::configure(basePath: dirname(__DIR__)) ]; foreach ($stalePatterns as $pattern) { - if (str_contains($message, $pattern)) { - return response('', 404); + if (str_contains($e->getMessage(), $pattern)) { + return true; } } + return false; + }; + + $exceptions->report(function (Throwable $e) use ($isStaleLivewireAsset) { + if ($isStaleLivewireAsset($e, request())) { + return false; + } + }); + + $exceptions->render(function (Throwable $e, Request $request) use ($isStaleLivewireAsset) { + if ($isStaleLivewireAsset($e, $request)) { + return response('', 404); + } + return null; }); })->create(); diff --git a/tests/Feature/LivewireStaleAssetTest.php b/tests/Feature/LivewireStaleAssetTest.php index ddea720..0d3634e 100644 --- a/tests/Feature/LivewireStaleAssetTest.php +++ b/tests/Feature/LivewireStaleAssetTest.php @@ -1,5 +1,6 @@ assertNotFound(); }); +it('does not report stale livewire css module exceptions to the logs', function () { + Log::spy(); + + $prefix = EndpointResolver::prefix(); + + $this->get($prefix.'/css/meetups--landingpage.css?v=1502173559') + ->assertNotFound(); + + Log::shouldNotHaveReceived('error'); + Log::shouldNotHaveReceived('critical'); + Log::shouldNotHaveReceived('emergency'); +}); + it('returns 404 for stale livewire global css module urls', function () { $prefix = EndpointResolver::prefix();