From 8ea284d776c78a7945787f39fa460cb000ca9bd9 Mon Sep 17 00:00:00 2001 From: pratik bhujel Date: Thu, 23 Apr 2026 19:20:58 +0545 Subject: [PATCH 1/3] Fix compiled path overrides after Blaze runtime resolution --- src/Runtime/BlazeRuntime.php | 23 +++++++++++++++++++---- tests/IntegrationTest.php | 21 ++++++++++++++++++++- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/Runtime/BlazeRuntime.php b/src/Runtime/BlazeRuntime.php index dd40220..c4a3671 100644 --- a/src/Runtime/BlazeRuntime.php +++ b/src/Runtime/BlazeRuntime.php @@ -18,8 +18,8 @@ */ 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 temporarily override this property. + // When it is null we always read the current view.compiled config. protected ?string $compiledPath = null; protected array $paths = []; @@ -48,7 +48,7 @@ public function ensureRequired(string $path, string $compiledPath): void } if (! file_exists($compiledPath) || filemtime($path) > filemtime($compiledPath)) { - $this->compiler->compile($path); + $this->getCompiler()->compile($path); } require $compiledPath; @@ -243,7 +243,22 @@ public function processPassthroughContent(string $method, string $content): stri private function getCompiledPath(): string { - return $this->compiledPath ??= config('view.compiled'); + return $this->compiledPath ?? config('view.compiled'); + } + + private function getCompiler(): Compiler + { + $compiler = app('blade.compiler'); + $compiledPath = $this->getCompiledPath(); + static $cachePath; + + $cachePath ??= new \ReflectionProperty($compiler, 'cachePath'); + + if ($cachePath->getValue($compiler) !== $compiledPath) { + $cachePath->setValue($compiler, $compiledPath); + } + + return $compiler; } /** diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index c63a08c..0b86255 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -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; @@ -92,4 +93,22 @@ public function render() BLADE, ['required' => true] ); -})->throwsNoExceptions(); \ No newline at end of file +})->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(' Date: Fri, 24 Apr 2026 22:56:57 +0545 Subject: [PATCH 2/3] Refresh compiled path cache per render --- src/BlazeServiceProvider.php | 2 ++ src/Runtime/BlazeRuntime.php | 14 +++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/BlazeServiceProvider.php b/src/BlazeServiceProvider.php index 10b8d9a..76fd6b2 100644 --- a/src/BlazeServiceProvider.php +++ b/src/BlazeServiceProvider.php @@ -87,6 +87,8 @@ protected function registerViewComposer(): void $view->getEngine()->getCompiler()->compile($view->getPath()); } + $runtime->syncCompiledPath(); + if ($blaze->isDebugging()) { $debugger->injectRenderTimer($view); diff --git a/src/Runtime/BlazeRuntime.php b/src/Runtime/BlazeRuntime.php index c4a3671..3e5e834 100644 --- a/src/Runtime/BlazeRuntime.php +++ b/src/Runtime/BlazeRuntime.php @@ -18,8 +18,8 @@ */ class BlazeRuntime { - // Tests and isolated rendering temporarily override this property. - // When it is null we always read the current view.compiled config. + // Lazily cached from config('view.compiled') on first access via __get. + // Tests and isolated rendering can still override it temporarily. protected ?string $compiledPath = null; protected array $paths = []; @@ -243,7 +243,7 @@ public function processPassthroughContent(string $method, string $content): stri private function getCompiledPath(): string { - return $this->compiledPath ?? config('view.compiled'); + return $this->compiledPath ??= config('view.compiled'); } private function getCompiler(): Compiler @@ -269,6 +269,14 @@ 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'); + } + /** * Clear the component data and slots stacks. */ From 0ff6d852e0c44f1a059bb3c5de319a3b196a756f Mon Sep 17 00:00:00 2001 From: pratik bhujel Date: Sat, 25 Apr 2026 08:22:53 +0545 Subject: [PATCH 3/3] Remove compiler helper from runtime path --- src/Runtime/BlazeRuntime.php | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/Runtime/BlazeRuntime.php b/src/Runtime/BlazeRuntime.php index 3e5e834..372ecf0 100644 --- a/src/Runtime/BlazeRuntime.php +++ b/src/Runtime/BlazeRuntime.php @@ -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; @@ -48,7 +47,7 @@ public function ensureRequired(string $path, string $compiledPath): void } if (! file_exists($compiledPath) || filemtime($path) > filemtime($compiledPath)) { - $this->getCompiler()->compile($path); + $this->compiler->compile($path); } require $compiledPath; @@ -246,21 +245,6 @@ private function getCompiledPath(): string return $this->compiledPath ??= config('view.compiled'); } - private function getCompiler(): Compiler - { - $compiler = app('blade.compiler'); - $compiledPath = $this->getCompiledPath(); - static $cachePath; - - $cachePath ??= new \ReflectionProperty($compiler, 'cachePath'); - - if ($cachePath->getValue($compiler) !== $compiledPath) { - $cachePath->setValue($compiler, $compiledPath); - } - - return $compiler; - } - /** * Set the application instance (used by Octane to swap in the sandbox). */ @@ -275,6 +259,14 @@ public function setApplication(Application $app): void 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); + } } /**