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
4 changes: 1 addition & 3 deletions src/BlazeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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));
}
});
Expand Down
53 changes: 41 additions & 12 deletions tests/IntegrationTest.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
<?php

use Illuminate\Contracts\View\Engine;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Blade;
use Livewire\Blaze\Blaze;

test('renders components', function () {
beforeEach(function () {
Artisan::call('view:clear');

view('inputs')->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 () {
Expand All @@ -46,7 +45,37 @@
});

test('supports php engine', function () {
// Make sure our hooks do not break views
// rendered using the regular php engine.
view('php-view')->render();
})->throwsNoExceptions();
})->throwsNoExceptions();

test('supports decorated engine', function () {
$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) {}

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 () {
// 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 {
return isset($data['__blaze']) ? 'BLAZE' : 'NO_BLAZE';
}
};
});

expect(view('antlers-view')->render())->toBe('NO_BLAZE');
});
1 change: 1 addition & 0 deletions tests/fixtures/views/antlers-view.antlers.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ title }}
2 changes: 0 additions & 2 deletions tests/fixtures/views/inputs.blade.php

This file was deleted.

4 changes: 4 additions & 0 deletions tests/fixtures/views/mix.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<x-input />
<x-memoizable.avatar />
<x-foldable.input />
<x-input-no-blaze />