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
2 changes: 2 additions & 0 deletions src/BlazeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ protected function registerViewComposer(): void
$view->getEngine()->getCompiler()->compile($view->getPath());
}

$runtime->syncCompiledPath();

if ($blaze->isDebugging()) {
$debugger->injectRenderTimer($view);

Expand Down
19 changes: 17 additions & 2 deletions src/Runtime/BlazeRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Illuminate\Support\Str;
use Illuminate\Support\ViewErrorBag;
use Illuminate\View\Compilers\BladeCompiler;
use Illuminate\View\Compilers\Compiler;
use Livewire\Blaze\BladeService;
use Livewire\Blaze\Support\Directives;
use Livewire\Blaze\Support\Utils;
Expand All @@ -19,7 +18,7 @@
class BlazeRuntime
{
// Lazily cached from config('view.compiled') on first access via __get.
// This ensures parallel-testing per-worker path overrides are respected.
// Tests and isolated rendering can still override it temporarily.
protected ?string $compiledPath = null;

protected array $paths = [];
Expand Down Expand Up @@ -254,6 +253,22 @@ public function setApplication(Application $app): void
$this->app = $app;
}

/**
* Refresh the cached compiled path from the current config.
*/
public function syncCompiledPath(): void
{
$this->compiledPath = config('view.compiled');

static $cachePath;

$cachePath ??= new \ReflectionProperty($this->compiler, 'cachePath');

if ($cachePath->getValue($this->compiler) !== $this->compiledPath) {
$cachePath->setValue($this->compiler, $this->compiledPath);
}
}

/**
* Clear the component data and slots stacks.
*/
Expand Down
21 changes: 20 additions & 1 deletion tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Illuminate\Contracts\View\Engine;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\File;
use Illuminate\View\Component;
use Livewire\Blaze\Blaze;
use Livewire\Blaze\BlazeManager;
Expand Down Expand Up @@ -92,4 +93,22 @@ public function render()
BLADE,
['required' => true]
);
})->throwsNoExceptions();
})->throwsNoExceptions();

test('uses the current compiled view path after blaze runtime is resolved', function () {
Blaze::optimize()->in(__DIR__.'/fixtures/components');

app(BlazeRuntime::class);

$compiledPath = sys_get_temp_dir() . '/blaze-compiled-' . bin2hex(random_bytes(4));

File::ensureDirectoryExists($compiledPath);

config()->set('view.compiled', $compiledPath);

try {
expect(view('mix')->render())->toContain('<input');
} finally {
File::deleteDirectory($compiledPath);
}
});
Loading