From 2213417987885a4beb2e43d0e65e13a9fc9594a4 Mon Sep 17 00:00:00 2001 From: pratik bhujel Date: Mon, 20 Apr 2026 10:29:12 +0545 Subject: [PATCH] Handle missing compiled views during folded expiry checks --- src/BlazeManager.php | 8 ++++++- tests/IntegrationTest.php | 46 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/BlazeManager.php b/src/BlazeManager.php index 49e0f0c..46a5807 100644 --- a/src/BlazeManager.php +++ b/src/BlazeManager.php @@ -294,7 +294,13 @@ public function viewContainsExpiredFrontMatter($view): bool $isExpired = false; if (! $expired) { - $contents = file_get_contents($compiled); + $contents = @file_get_contents($compiled); + + if ($contents === false) { + $compiler->compile($path); + + $contents = file_get_contents($compiled); + } $isExpired = (new FrontMatter)->sourceContainsExpiredFoldedDependencies($contents); } diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index c63a08c..c880535 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -5,6 +5,9 @@ use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Blade; use Illuminate\View\Component; +use Illuminate\View\Compilers\BladeCompiler; +use Illuminate\View\Engines\CompilerEngine; +use Illuminate\View\View; use Livewire\Blaze\Blaze; use Livewire\Blaze\BlazeManager; use Livewire\Blaze\Runtime\BlazeRuntime; @@ -36,6 +39,47 @@ view('mix')->render(); })->throwsNoExceptions(); +test('recompiles when a compiled view disappears while checking folded dependencies', function () { + $path = storage_path('framework/testing/blaze-missing-compiled-view.blade.php'); + + app('files')->ensureDirectoryExists(dirname($path)); + app('files')->put($path, 'Hello'); + + $compiler = new class(app('files'), config('view.compiled')) extends BladeCompiler { + public bool $deleteCompiledView = false; + + public function isExpired($path) + { + $expired = parent::isExpired($path); + + if (! $expired && $this->deleteCompiledView) { + unlink($this->getCompiledPath($path)); + } + + return $expired; + } + }; + + $compiler->compile($path); + touch($path, time() - 10); + touch($compiler->getCompiledPath($path), time()); + + $compiler->deleteCompiledView = true; + + $view = new View( + app('view'), + new CompilerEngine($compiler), + 'blaze-missing-compiled-view', + $path, + ); + + expect(app(BlazeManager::class)->viewContainsExpiredFrontMatter($view))->toBeFalse(); + expect(file_exists($compiler->getCompiledPath($path)))->toBeTrue(); + + app('files')->delete($path); + app('files')->delete($compiler->getCompiledPath($path)); +}); + test('supports php engine', function () { view('php-view')->render(); })->throwsNoExceptions(); @@ -92,4 +136,4 @@ public function render() BLADE, ['required' => true] ); -})->throwsNoExceptions(); \ No newline at end of file +})->throwsNoExceptions();