Skip to content

Fix Statamic serialization issue#89

Merged
ganyicz merged 1 commit intomainfrom
filip/fix-statamic-antlers
Feb 28, 2026
Merged

Fix Statamic serialization issue#89
ganyicz merged 1 commit intomainfrom
filip/fix-statamic-antlers

Conversation

@ganyicz
Copy link
Collaborator

@ganyicz ganyicz commented Feb 28, 2026

The scenario

Installing Blaze alongside Statamic and visiting any Statamic page that uses a {{ nocache }} tag throws an exception

Serialization of 'Closure' is not allowed
  at Illuminate\Cache\FileStore.php:92

The problem

View::share() injects data into every view engine registered in Laravel -- not just Blade. BlazeRuntime was shared globally via View::share('__blaze', ...), which meant it landed in Statamic's Antlers template context too.

Statamic's {{ nocache }} feature serializes the template context so it can replay dynamic sections from cache. BlazeRuntime holds the Application container and the Blade compiler, both of which contain Closures that can't be serialized:

This happened even with BLAZE_ENABLED=false because the View::share() call ran unconditionally in boot().

The solution

Replace View::share() with a View::composer('*', ...) that checks $view->getEngine() instanceof CompilerEngine before injecting __blaze. This scopes the runtime to Blade views only and keeps it out of Antlers and any other non-Blade engine.

View::composer('*', function (\Illuminate\View\View $view) {
    // Avoid injecting the BlazeRuntime into non-Blade views (like Statamic's Antlers)
    if ($view->getEngine() instanceof CompilerEngine) {
        $view->with('__blaze', $this->app->make(BlazeRuntime::class));
    }
});

Fixes #83

@ganyicz ganyicz merged commit 334c0bc into main Feb 28, 2026
6 checks passed
@ganyicz ganyicz deleted the filip/fix-statamic-antlers branch February 28, 2026 00:54
@ganyicz ganyicz mentioned this pull request Feb 28, 2026
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.

Exception "Serialization of 'Closure' is not allowed" with Statamic + Peak

1 participant