Skip to content

Commit

Permalink
[Bug] Auto Inject Assets: Only if component rendered
Browse files Browse the repository at this point in the history
Regression from 65ce494 rappasoft#1371

Fixes: rappasoft#1587

Check if component is instanceof DataTableComponent so as not to inject on every livewire page, only ones with a datatable component
  • Loading branch information
yparitcher committed May 7, 2024
1 parent 2bd477e commit e36e97b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Features/AutoInjectRappasoftAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -36,6 +37,10 @@ public static function provide(): void
return;
}

if (! static::$hasRenderedAComponentThisRequest) {
return;
}

// If All Scripts Have Been Rendered - Return
if (
(
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e36e97b

Please sign in to comment.