diff --git a/src/Http/Middleware/AssetInjection.php b/src/Http/Middleware/AssetInjection.php index d122905..99f205c 100644 --- a/src/Http/Middleware/AssetInjection.php +++ b/src/Http/Middleware/AssetInjection.php @@ -10,26 +10,28 @@ public function handle($request, Closure $next) { $response = $next($request); - // return $response; if (! method_exists($response, 'getContent')) { return $response; } $content = $response->getContent(); - if (! is_string($content)) { + if (! $content) { return $response; } - - $castsScripts = ''; + + $castsScripts = ''; $livewireScripts = (new LivewireManager)->scripts(); $livewireStyles = (new LivewireManager)->styles(); - $html = new HtmlPageCrawler($content); + $html = (new HtmlPageCrawler)->create($content); + + if (! $html) { + return $response; + } - if ($this->isNotOnErrorPage($html) - && $html->filter("html > head")->count() - ) { + if ($html->filter("html > head")->count()) { + $html->filter("html > head")->append($livewireStyles); $html->filter("html > head")->append($livewireStyles); $html->filter("html > body")->append($livewireScripts); $html->filter("html > body")->append($castsScripts); @@ -42,9 +44,4 @@ public function handle($request, Closure $next) return $response; } - - protected function isNotOnErrorPage(string $html) : bool - { - return strpos($html, "window.Ignition") === false; - } }