From 158a4ab531ba253f3229f9fe91b8ea333478deab Mon Sep 17 00:00:00 2001 From: Filip Ganyicz Date: Sat, 12 Sep 2026 16:15:21 +0200 Subject: [PATCH 1/2] Render components via view --- src/Compiler/Wrapper.php | 11 +++++------ tests/Compiler/WrapperTest.php | 10 +++++++--- tests/IntegrationTest.php | 12 ++++++++++++ tests/fixtures/views/components/alert.blade.php | 1 + workbench/app/View/Components/Alert.php | 8 ++++++-- 5 files changed, 31 insertions(+), 11 deletions(-) create mode 100644 tests/fixtures/views/components/alert.blade.php diff --git a/src/Compiler/Wrapper.php b/src/Compiler/Wrapper.php index 12484ec3..1f5c5f12 100644 --- a/src/Compiler/Wrapper.php +++ b/src/Compiler/Wrapper.php @@ -54,9 +54,10 @@ public function wrap(string $compiled, string $path, ?string $source = null): st $output = ''; - $output .= '<'.'?php' . "\n"; - $output .= $imports; - $output .= 'if (!function_exists(\''.$name.'\')):'."\n"; + $output .= $imports ? "\n" : ''; + $output .= ''."\n"; + $output .= $compiled; + $output .= 'directive('aware', $this->awareCompiler->compile(...)) ->compile($compiled); - $compiled = $this->blade->restoreRawBlocks($compiled); - $output .= $compiled; $output .= ''; - return $output; + return $this->blade->restoreRawBlocks($output); } protected function globalVariables(string $source, string $compiled): string diff --git a/tests/Compiler/WrapperTest.php b/tests/Compiler/WrapperTest.php index 5d3e940f..98448cf6 100644 --- a/tests/Compiler/WrapperTest.php +++ b/tests/Compiler/WrapperTest.php @@ -13,7 +13,9 @@ $wrapped = app(Wrapper::class)->wrap($source, $path, $source); expect($wrapped)->toEqualCollapsingWhitespace(join('', [ - ' ', + $source, + 'env; ', 'if (($__data[\'attributes\'] ?? null) instanceof \Illuminate\View\ComponentAttributeBag) { $__data = $__data + $__data[\'attributes\']->all(); unset($__data[\'attributes\']); } ', 'extract($__slots, EXTR_SKIP); unset($__slots); ', @@ -39,7 +41,9 @@ $wrapped = app(Wrapper::class)->wrap($source, $path, $source); expect($wrapped)->toEqualCollapsingWhitespace(join('', [ - ' ', + $source, + 'env; ', 'if (($__data[\'attributes\'] ?? null) instanceof \Illuminate\View\ComponentAttributeBag) { $__data = $__data + $__data[\'attributes\']->all(); unset($__data[\'attributes\']); } ', 'extract($__slots, EXTR_SKIP); unset($__slots); ', @@ -99,7 +103,7 @@ // Replace raw @php blocks for placeholders. This normally happens in BlazeManager before the template gets to the Wrapper $source = app(BladeService::class)->preStoreUncompiledBlocks($statement); - expect(app(Wrapper::class)->wrap($source, '', $source))->toStartWith("wrap($source, '', $source))->toStartWith(""); })->with([ ['@use(\'App\Models\User\')'], ['@php use \App\Models\User; @endphp'], diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index 25c902a5..c7c11b12 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -36,6 +36,18 @@ view('mix')->render(); })->throwsNoExceptions(); +test('renders components as views', function () { + Blaze::optimize()->in(fixture_path('views/components')); + + expect(view('components.alert', ['message' => 'Hello world'])->render())->toBe('
Hello world
'); +}); + +test('renders class based component', function () { + Blaze::optimize()->in(fixture_path('views/components')); + + expect(Blade::render(''))->toBe('
Hello world
'); +}); + test('supports php engine', function () { view('php-view')->render(); })->throwsNoExceptions(); diff --git a/tests/fixtures/views/components/alert.blade.php b/tests/fixtures/views/components/alert.blade.php new file mode 100644 index 00000000..2e564ad8 --- /dev/null +++ b/tests/fixtures/views/components/alert.blade.php @@ -0,0 +1 @@ +
{{ $message }}
\ No newline at end of file diff --git a/workbench/app/View/Components/Alert.php b/workbench/app/View/Components/Alert.php index 111ad9f4..7286519f 100644 --- a/workbench/app/View/Components/Alert.php +++ b/workbench/app/View/Components/Alert.php @@ -6,8 +6,12 @@ class Alert extends Component { - public function render(): string + public function __construct( + public string $message, + ) {} + + public function render() { - return '
'; + return view('components.alert'); } } From eb0dbee4d8b5c0377d6da96a58f5adf808cb690b Mon Sep 17 00:00:00 2001 From: Filip Ganyicz Date: Sat, 12 Sep 2026 19:17:49 +0200 Subject: [PATCH 2/2] Update README.md --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index 5371a0e3..c8d9caa9 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,6 @@ Component-level `@blaze` directives override directory-level settings. Blaze supports all essential features and produces HTML output identical to Blade. While the focus is on maximizing performance with full compatibility, there are some limitations to be aware of: -- **Class-based components** are not supported - **The `$component` variable** is not available - **View composers / creators / lifecycle events** do not fire - **Auto-injecting `View::share()` variables** is not supported @@ -123,9 +122,6 @@ Blaze supports all essential features and produces HTML output identical to Blad - **Cross boundary `@aware`** between Blade and Blaze Both parent and child must use Blaze for values to propagate -- **Rendering Blaze components using `view()`** will not work - - Blaze components can only be rendered using the component tag # Optimization Strategies