diff --git a/src/BlazeManager.php b/src/BlazeManager.php index 49e0f0c..eef12d8 100644 --- a/src/BlazeManager.php +++ b/src/BlazeManager.php @@ -276,32 +276,21 @@ public function collectAndAppendFrontMatter($template, $callback) public function viewContainsExpiredFrontMatter($view): bool { $engine = $view->getEngine(); - - if (! $engine instanceof CompilerEngine) { - return false; - } - $path = $view->getPath(); if (isset($this->expiredMemo[$path])) { return $this->expiredMemo[$path]; } - $compiler = $engine->getCompiler(); - $compiled = $compiler->getCompiledPath($path); - $expired = $compiler->isExpired($path); - - $isExpired = false; - - if (! $expired) { - $contents = file_get_contents($compiled); - - $isExpired = (new FrontMatter)->sourceContainsExpiredFoldedDependencies($contents); + if (! $engine instanceof CompilerEngine) { + return $this->expiredMemo[$path] = false; } - $this->expiredMemo[$path] = $isExpired; + $compiler = $engine->getCompiler(); + $compiled = $compiler->getCompiledPath($path); + $expired = $compiler->isExpired($path) ? false : (new FrontMatter)->containsExpiredFoldedDependencies($compiled); - return $isExpired; + return $this->expiredMemo[$path] = $expired; } /** diff --git a/src/FrontMatter.php b/src/FrontMatter.php index abb7d99..13f6636 100644 --- a/src/FrontMatter.php +++ b/src/FrontMatter.php @@ -28,10 +28,16 @@ public function compileFromEvents(array $events): string } /** - * Check if any folded component referenced in the source has been modified. + * Check if any folded component referenced in the compiled file has been modified. */ - public function sourceContainsExpiredFoldedDependencies(string $source): bool + public function containsExpiredFoldedDependencies(string $path): bool { + $source = @file_get_contents($path); + + if ($source === false) { + return false; + } + $foldedComponents = $this->parseFromTemplate($source); if (empty($foldedComponents)) { diff --git a/tests/BlazeManagerTest.php b/tests/BlazeManagerTest.php index 7ca06a6..52a5947 100644 --- a/tests/BlazeManagerTest.php +++ b/tests/BlazeManagerTest.php @@ -1,6 +1,10 @@ Artisan::call('view:clear')); test('compile preserves php directives', function () { $input = '@php /* uncompiled */ @endphp'; @@ -26,4 +30,27 @@ // compileForUnblaze should only store raw blocks, not restore them. // They will be restored in the parent compile() method. expect(Blaze::compileForUnblaze($input))->toBe('@__raw_block_0__@'); -}); \ No newline at end of file +}); + +test('viewContainsExpiredFrontMatter returns true when folded component source is updated', function () { + $component = fixture_path('views/components/foldable/input.blade.php'); + $modified = filemtime($component); + $manager = app(BlazeManager::class); + $view = view('blaze'); + + $view->render(); + $manager->flushState(); + + touch($component, $modified + 10); + + expect($manager->viewContainsExpiredFrontMatter($view))->toBeTrue(); + + touch($component, $modified); +}); + +test('viewContainsExpiredFrontMatter returns false when view isnt compiled', function () { + $manager = app(BlazeManager::class); + $view = view('blaze'); + + expect($manager->viewContainsExpiredFrontMatter($view))->toBeFalse(); +});