Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions src/BlazeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
10 changes: 8 additions & 2 deletions src/FrontMatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
29 changes: 28 additions & 1 deletion tests/BlazeManagerTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php

use Illuminate\Support\Facades\Artisan;
use Livewire\Blaze\Blaze;
use Livewire\Blaze\BlazeManager;

beforeEach(fn () => Artisan::call('view:clear'));

test('compile preserves php directives', function () {
$input = '@php /* uncompiled */ @endphp';
Expand All @@ -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__@');
});
});

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();
});
Loading