Skip to content

Conversation

@richbleeker
Copy link

Description

This PR fixes the Call to undefined method Illuminate\View\Engines\FileEngine::getCompiler() error that occurs when Blaze processes views using non-compiler engines.

Fixes #12

Problem

The viewContainsExpiredFrontMatter() method assumes all view engines have a getCompiler() method, but Laravel has multiple view engines:

  • CompilerEngine - Has getCompiler() (used for .blade.php files)
  • FileEngine - Does NOT have getCompiler() (used for plain .php files)
  • PhpEngine - Does NOT have getCompiler()

This causes errors when:

  • Email notifications are sent (especially in queued jobs)
  • Plain PHP views are rendered
  • Any view using FileEngine or PhpEngine is processed

Solution

Added a method_exists() check before calling getCompiler(). For engines without a compiler, it returns false (no expired frontmatter).

$engine = $view->getEngine();

// Only CompilerEngine has the getCompiler() method.
// FileEngine and PhpEngine do not have this method, so we should skip checking them.
if (! method_exists($engine, 'getCompiler')) {
    $this->expiredMemo[$path] = false;
    return false;
}

This is correct because non-compiler engines don't compile templates, so they can't have expired frontmatter.

Why This Approach?

Unlike PR #15 which always checks the Blade compiler regardless of the view's actual engine, this fix:

  1. Respects the actual engine being used by the view
  2. Correctly handles engines that don't have compilers
  3. Is more explicit about why we're skipping the check
  4. Doesn't bypass Laravel's view engine architecture
  5. Properly caches results to avoid repeated checks

Tests

Added comprehensive test coverage in tests/FileEngineTest.php:

  • ✅ Handles FileEngine views without errors
  • ✅ Caches results for FileEngine views
  • ✅ Still works correctly with CompilerEngine (Blade views)

All 141 tests pass (138 existing + 3 new).

Tested On

  • PHP 8.2.28
  • Laravel 12.0
  • Livewire Blaze (latest main branch)
  • Real-world scenario: Queued email notifications with inline images

This fix resolves the 'Call to undefined method Illuminate\View\Engines\FileEngine::getCompiler()' error that occurs when Blaze processes views that use FileEngine (plain PHP templates) instead of CompilerEngine (Blade templates).

The issue manifests when:
- Email notifications are sent (especially in queued jobs)
- Plain PHP views are rendered
- Any view using FileEngine or PhpEngine is processed

The fix checks if the view engine has the getCompiler() method before attempting to call it. For engines without a compiler (FileEngine, PhpEngine), it returns false, indicating no expired frontmatter to check.

This approach is correct because:
1. Non-compiler engines don't compile templates, so they can't have expired frontmatter
2. It's safer and more explicit than catching exceptions
3. It properly caches the result to avoid repeated checks

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vendor\livewire\blaze\src\BlazeManager.php:66

1 participant