Describe the bug
Blaze::optimize()->in() compiles every template in it's target directory, with no way to know
which ones a class will later render.
If the target directory contains any class-based templates they render as empty strings + no exception + 200 response.
By default Laravel's make:component also writes class-based templates to
resources/views/components (same directory Blaze README uses to illustrate optimizing by directory.)
Reproduce
php artisan make:component Alert (no flags, class-based)
- Class: add
public string $message
- Template:
<div>{{ $message }}</div>
- Provider:
Blaze::optimize()->in(resource_path('views/components'));
php artisan view:clear
- Render
<x-alert message="hello" />
Result
Same component & input, toggling only BLAZE_ENABLED:
false -> <div>hello</div>
true -> (empty, no exception)
Cause
Compiled artefact for the class-based component's template:
<?php
if (!function_exists('_1365a3bc689a48ca5ab34037d510a76f')):
function _1365a3bc689a48ca5ab34037d510a76f($__blaze, $__data = [], ...) {
// ...
echo ltrim(ob_get_clean());
} endif; ?>
<?php /**PATH .../components/blaze-repro.blade.php ENDPATH**/ ?>
Component::render() returns a view, then CompilerEngine::get() and
PhpEngine::evaluatePath() require the file and capture output. Function defined,
nothing printed, Blaze runtime never invoked.
Not covered by #146
#146 handled tag resolution, adding a class check inside componentNameToPath() so it
returns '' for class-based names and a Blaze parent won't inline <x-alert>.
This is file compilation instead. The pre-compilation hook wraps every Blaze::optimize()->in() template regardless of what renders it, and no tag is involved. Reproduced on v1.0.18, which includes #146.
Environment
Laravel 13.31.0, PHP 8.4.6, livewire/blaze v1.0.18
Describe the bug
Blaze::optimize()->in()compiles every template in it's target directory, with no way to knowwhich ones a class will later render.
If the target directory contains any class-based templates they render as empty strings + no exception + 200 response.
By default Laravel's
make:componentalso writes class-based templates toresources/views/components(same directory Blaze README uses to illustrate optimizing by directory.)Reproduce
php artisan make:component Alert(no flags, class-based)public string $message<div>{{ $message }}</div>Blaze::optimize()->in(resource_path('views/components'));php artisan view:clear<x-alert message="hello" />Result
Same component & input, toggling only
BLAZE_ENABLED:Cause
Compiled artefact for the class-based component's template:
Component::render()returns a view, thenCompilerEngine::get()andPhpEngine::evaluatePath()require the file and capture output. Function defined,nothing printed, Blaze runtime never invoked.
Not covered by #146
#146 handled tag resolution, adding a class check inside
componentNameToPath()so itreturns
''for class-based names and a Blaze parent won't inline<x-alert>.This is file compilation instead. The pre-compilation hook wraps every
Blaze::optimize()->in()template regardless of what renders it, and no tag is involved. Reproduced on v1.0.18, which includes #146.Environment
Laravel 13.31.0, PHP 8.4.6, livewire/blaze v1.0.18