Exclude Blaze scope variables from Volt fragment arguments#188
Open
calebporzio wants to merge 1 commit into
Open
Exclude Blaze scope variables from Volt fragment arguments#188calebporzio wants to merge 1 commit into
calebporzio wants to merge 1 commit into
Conversation
Volt compiles @Volt fragments (used in Folio pages) into a Livewire mount call that captures the surrounding template scope via get_defined_vars(). Blaze introduces variables into that scope (the $__blaze runtime plus call-site temporaries like $__attrs{hash} and $__slots{hash}) that Volt then forwards to Livewire as component arguments. Livewire stores the unrecognized arguments in the snapshot memo, and the serialized objects don't survive the JSON round trip on the next request, corrupting the snapshot checksum and throwing CorruptComponentPayloadException on any interaction. Fixes #187 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
Benchmark Result: Default
Median of 10 attempts (* = outlier, excluded from result), 5000 iterations x 10 rounds, 46.92s total To run a specific benchmark, comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #187
The problem
Using Blaze on an app with a Laravel Folio page that embeds a Volt component via
@voltthrowsCorruptComponentPayloadExceptionon any interaction with the component.Root cause
Volt compiles
@voltfragments into a Livewire mount call that captures the entire surrounding template scope:Volt filters out the framework variables it knows about (
__env,__data,errors, etc.), but Blaze introduces new variables into template scope that aren't on that list:$__blaze— the shared runtime, injected into every view$__attrs{hash}/$__slots{hash}(and their stacks) — call-site temporaries emitted around optimized component calls (e.g. a layout component wrapping the fragment)Volt forwards these to Livewire as component arguments. Since they don't match any public property, Livewire stores them as HTML attributes in the snapshot memo. The serialized runtime contains empty objects (
{}) that decode to[]on the next request, so the re-encoded snapshot no longer matches its checksum — and Livewire throws the corrupt payload exception.This also explains why scoping Blaze to specific directories didn't help (
$__blazeis injected into every view while Blaze is enabled) and why only disabling Blaze entirely worked.The fix
When Blaze's pre-compilation hook sees Volt's generated scope capture (Volt's precompiler always runs first, since Blaze registers its hook after the app is booted), it wraps
get_defined_vars()so Blaze's internal variables are filtered out before Volt ever sees them:User variables in scope (e.g. data passed from Folio's
render()) still flow through exactly as before.Verification
Reproduced against a fresh Laravel 13 app (Livewire 4.3.3, Volt 1.10.5, Folio 1.1) with a Folio page embedding a
@voltcounter inside a Blaze-optimized layout component:POST /livewire/update→ 500CorruptComponentPayloadExceptionPOST /livewire/update→ 200, counter increments, and the snapshot memo is byte-for-byte identical in shape to running with Blaze disabled (including intentionally captured scope variables like Foliorender()data)🤖 Generated with Claude Code