Skip to content

Optimizing directory with Blaze::optimize()->in() renders class-based templates as empty output #210

Description

@Wraxton

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

  1. php artisan make:component Alert (no flags, class-based)
  2. Class: add public string $message
  3. Template: <div>{{ $message }}</div>
  4. Provider: Blaze::optimize()->in(resource_path('views/components'));
  5. php artisan view:clear
  6. 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions