Skip to content

Fix path resolution during optimize with Sentry#88

Merged
ganyicz merged 2 commits intomainfrom
filip/fix-sentry
Feb 28, 2026
Merged

Fix path resolution during optimize with Sentry#88
ganyicz merged 2 commits intomainfrom
filip/fix-sentry

Conversation

@ganyicz
Copy link
Collaborator

@ganyicz ganyicz commented Feb 28, 2026

The scenario

Running php artisan optimize with Sentry installed produces broken compiled templates — components aren't compiled to functions.

Running php artisan view:cache alone works fine.

The problem

app('blade.compiler')->getPath() always returns null during optimize, so we skip the wrap() call entirely. This happens because the instance resolved via app('blade.compiler') is different from the one that started view compilation.

Sentry forces early resolution of the blade engine during boot via app('view')->getEngineResolver()->resolve('blade'). When php artisan optimize runs:

  1. config:cache — swaps the application instance in the container.
  2. view:cache — compiles views using the original app instance from $this->laravel.

Because of the early resolution, Laravel doesn't resolve the blade compiler again from the new instance and instead uses the stale one. Calling app('blade.compiler') returns a new instance that has no path set.

The solution

We capture the compiler reference once in BladeService::earliestPreCompilationHook() and thread $path through the entire blaze pipeline, instead of resolving app('blade.compiler') inside each BlazeManager method:

$compiler = app('blade.compiler');

$compiler->prepareStringsForCompilationUsing(function ($input) use ($callback, $compiler) {
    $path = $compiler->getPath();

    return $callback($input, $path);
});

Fixes #43

@ganyicz ganyicz merged commit 7b64de5 into main Feb 28, 2026
6 checks passed
@ganyicz ganyicz deleted the filip/fix-sentry branch February 28, 2026 00:15
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.

Output broken when running php artisan optimize with Sentry installed

1 participant