From 6b4d158a04b753649a15745998053a7f21b37cc5 Mon Sep 17 00:00:00 2001 From: Yechiel Date: Tue, 5 Mar 2024 10:58:47 -0500 Subject: [PATCH] [Bug] Auto Inject Assets: Only if component rendered Regression from 65ce4947ab58b77fb3e454423202edd17e414e49 #1371 Fixes: #1587 Check if component is instanceof DataTableComponent so as not to inject on every livewire page, only ones with a datatable component --- src/Features/AutoInjectRappasoftAssets.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Features/AutoInjectRappasoftAssets.php b/src/Features/AutoInjectRappasoftAssets.php index 73e2c5e12..0b54aa6eb 100644 --- a/src/Features/AutoInjectRappasoftAssets.php +++ b/src/Features/AutoInjectRappasoftAssets.php @@ -4,6 +4,7 @@ use Illuminate\Foundation\Http\Events\RequestHandled; use Livewire\ComponentHook; +use Rappasoft\LaravelLivewireTables\DataTableComponent; use Rappasoft\LaravelLivewireTables\Mechanisms\RappasoftFrontendAssets; use function Livewire\on; @@ -36,6 +37,10 @@ public static function provide(): void return; } + if (! static::$hasRenderedAComponentThisRequest) { + return; + } + // If All Scripts Have Been Rendered - Return if ( ( @@ -73,7 +78,9 @@ public static function provide(): void public function dehydrate(): void { - static::$hasRenderedAComponentThisRequest = true; + if ($this->component instanceof DataTableComponent){ + static::$hasRenderedAComponentThisRequest = true; + } } public static function injectAssets(mixed $html): string