Skip to content
Closed
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
17 changes: 17 additions & 0 deletions src/BlazeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

use Livewire\Blaze\Compiler\Profiler;
use Livewire\Blaze\Runtime\BlazeRuntime;
use Illuminate\Console\Events\CommandFinished;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\View;
use Illuminate\View\Component;
use Livewire\Blaze\Memoizer\Memo;

class BlazeServiceProvider extends ServiceProvider
Expand Down Expand Up @@ -47,6 +49,7 @@ public function boot(): void
$this->registerBladeMacros();
$this->interceptBladeCompilation();
$this->registerDebuggerMiddleware();
$this->registerViewClearListener();
$this->registerOctaneListener();
}

Expand Down Expand Up @@ -167,6 +170,20 @@ protected function registerDebuggerMiddleware(): void
});
}

/**
* Register a listener for the view:clear command to flush the compiled cache.
*/
protected function registerViewClearListener(): void
{
Event::listen(CommandFinished::class, function (CommandFinished $event) {
if ($event->command === 'view:clear') {
$this->app->make(BlazeRuntime::class)->flushCompiled();

Component::flushCache();
}
});
}

/**
* Reset Blaze state between Octane requests.
*/
Expand Down
21 changes: 16 additions & 5 deletions src/Runtime/BlazeRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,6 @@ public function processPassthroughContent(string $method, string $content): stri
return $content;
}

private function getCompiledPath(): string
{
return $this->compiledPath ??= config('view.compiled');
}

/**
* Set the application instance (used by Octane to swap in the sandbox).
*/
Expand All @@ -258,6 +253,14 @@ public function flushState(): void
$this->slotsStack = [];
}

/**
* Clear the in-memory compilation cache.
*/
public function flushCompiled(): void
{
$this->compiled = [];
}

/**
* Lazy-load properties whose canonical values are set after BlazeRuntime is constructed
* ($errors by middleware, compiledPath by parallel testing infrastructure).
Expand All @@ -270,4 +273,12 @@ public function __get(string $name): mixed
default => throw new \InvalidArgumentException("Property {$name} does not exist"),
};
}

/**
* Get the compiled path.
*/
private function getCompiledPath(): string
{
return $this->compiledPath ??= config('view.compiled');
}
}
13 changes: 12 additions & 1 deletion tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

use Illuminate\Container\Container;
use Illuminate\Contracts\View\Engine;
use Illuminate\Foundation\Testing\WithConsoleEvents;
use Illuminate\Support\Facades\Artisan;
use Livewire\Blaze\Blaze;
use Livewire\Blaze\BlazeManager;

uses(WithConsoleEvents::class);

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

test('renders components', function () {
Expand All @@ -14,13 +17,21 @@

test('renders components with blaze off', function () {
Blaze::disable();

view('mix')->render();
})->throwsNoExceptions();

test('renders components with blaze off and debug mode on', function () {
Blaze::disable();
Blaze::debug();

view('mix')->render();
})->throwsNoExceptions();

test('renders components after clearing views', function () {
view('mix')->render();

Artisan::call('view:clear');

view('mix')->render();
})->throwsNoExceptions();
Expand Down