From 6ae1a773e942b7156ed75dc568b466a1b0f538a5 Mon Sep 17 00:00:00 2001 From: Filip Ganyicz Date: Sun, 1 Mar 2026 21:35:43 +0100 Subject: [PATCH 1/3] Fix BlazeRuntime injection --- src/BlazeServiceProvider.php | 4 +- tests/IntegrationTest.php | 49 +++++++++++++++---- .../fixtures/views/antlers-view.antlers.html | 1 + tests/fixtures/views/inputs.blade.php | 2 - tests/fixtures/views/mix.blade.php | 4 ++ 5 files changed, 45 insertions(+), 15 deletions(-) create mode 100644 tests/fixtures/views/antlers-view.antlers.html delete mode 100644 tests/fixtures/views/inputs.blade.php create mode 100644 tests/fixtures/views/mix.blade.php diff --git a/src/BlazeServiceProvider.php b/src/BlazeServiceProvider.php index 3af4afe5..35036f98 100644 --- a/src/BlazeServiceProvider.php +++ b/src/BlazeServiceProvider.php @@ -7,7 +7,6 @@ use Illuminate\Support\ServiceProvider; use Illuminate\Support\Facades\Blade; use Illuminate\Support\Facades\View; -use Illuminate\View\Engines\CompilerEngine; class BlazeServiceProvider extends ServiceProvider { @@ -58,8 +57,7 @@ protected function registerBlazeRuntime(): void return; } - // Avoid injecting the BlazeRuntime into non-Blade views (like Statamic's Antlers) - if ($view->getEngine() instanceof CompilerEngine) { + if (str_ends_with($view->getPath(), '.blade.php')) { $view->with('__blaze', $this->app->make(BlazeRuntime::class)); } }); diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index a9ae7aa9..b1f3cbce 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -1,30 +1,29 @@ render(); +}); + +test('renders components', function () { + view('mix')->render(); })->throwsNoExceptions(); test('renders components with blaze off', function () { - Artisan::call('view:clear'); - Blaze::disable(); - view('inputs')->render(); + view('mix')->render(); })->throwsNoExceptions(); test('renders components with blaze off and debug mode on', function () { - Artisan::call('view:clear'); - Blaze::disable(); Blaze::debug(); - view('inputs')->render(); + view('mix')->render(); })->throwsNoExceptions(); test('ignores verbatim blocks', function () { @@ -49,4 +48,34 @@ // Make sure our hooks do not break views // rendered using the regular php engine. view('php-view')->render(); -})->throwsNoExceptions(); \ No newline at end of file +})->throwsNoExceptions(); + +test('supports decorated engine', function () { + $resolver = app('view.engine.resolver'); + $blade = $resolver->resolve('blade'); + + $resolver->register('blade', function () use ($blade) { + return new class($blade) implements Engine { + public function __construct(private Engine $engine) {} + + public function get($path, array $data = []): string { + return $this->engine->get($path, $data); + } + }; + }); + + view('mix')->render(); +})->throwsNoExceptions(); + +test('does not inject __blaze into non-blade engine views', function () { + // We don't want to inject __blaze into Statamic because + app('view')->addExtension('antlers.html', 'antlers', function () { + return new class implements Engine { + public function get($path, array $data = []): string { + return isset($data['__blaze']) ? 'BLAZE' : 'NO_BLAZE'; + } + }; + }); + + expect(view('antlers-view')->render())->toBe('NO_BLAZE'); +}); \ No newline at end of file diff --git a/tests/fixtures/views/antlers-view.antlers.html b/tests/fixtures/views/antlers-view.antlers.html new file mode 100644 index 00000000..6d5a89f8 --- /dev/null +++ b/tests/fixtures/views/antlers-view.antlers.html @@ -0,0 +1 @@ +{{ title }} diff --git a/tests/fixtures/views/inputs.blade.php b/tests/fixtures/views/inputs.blade.php deleted file mode 100644 index 0a87d0ee..00000000 --- a/tests/fixtures/views/inputs.blade.php +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/tests/fixtures/views/mix.blade.php b/tests/fixtures/views/mix.blade.php new file mode 100644 index 00000000..7ea6ad13 --- /dev/null +++ b/tests/fixtures/views/mix.blade.php @@ -0,0 +1,4 @@ + + + + \ No newline at end of file From 838f8bee62a433a39c3e4acc722608711e82f9ee Mon Sep 17 00:00:00 2001 From: Filip Ganyicz Date: Sun, 1 Mar 2026 21:51:23 +0100 Subject: [PATCH 2/3] Fix fixture --- tests/fixtures/views/mix.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fixtures/views/mix.blade.php b/tests/fixtures/views/mix.blade.php index 7ea6ad13..35084dae 100644 --- a/tests/fixtures/views/mix.blade.php +++ b/tests/fixtures/views/mix.blade.php @@ -1,4 +1,4 @@ - + \ No newline at end of file From cd8191f4b9991ae0b535167fb9d6112352e09e29 Mon Sep 17 00:00:00 2001 From: Filip Ganyicz Date: Sun, 1 Mar 2026 21:52:23 +0100 Subject: [PATCH 3/3] Refactor --- tests/IntegrationTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index b1f3cbce..a061a619 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -45,8 +45,6 @@ }); test('supports php engine', function () { - // Make sure our hooks do not break views - // rendered using the regular php engine. view('php-view')->render(); })->throwsNoExceptions(); @@ -54,6 +52,7 @@ $resolver = app('view.engine.resolver'); $blade = $resolver->resolve('blade'); + // This replicates how Sentry wraps the blade engine... $resolver->register('blade', function () use ($blade) { return new class($blade) implements Engine { public function __construct(private Engine $engine) {} @@ -68,7 +67,8 @@ public function get($path, array $data = []): string { })->throwsNoExceptions(); test('does not inject __blaze into non-blade engine views', function () { - // We don't want to inject __blaze into Statamic because + // Statamic serializes all view data, we need to make sure + // we don't inject BlazeRuntime which is not serializable. app('view')->addExtension('antlers.html', 'antlers', function () { return new class implements Engine { public function get($path, array $data = []): string {