Fix Livewire smart keys poisoning - #205
Merged
Merged
Conversation
Contributor
Benchmark Result: Default
Median of 10 attempts, 5000 iterations x 10 rounds, 47.86s total To run a specific benchmark, comment |
ganyicz
marked this pull request as draft
August 15, 2026 17:45
Collaborator
Author
|
/benchmark compilation |
Contributor
Benchmark Result: Compilation
Median of 10 attempts, 5000 iterations x 10 rounds, 5.3s 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.
The scenario
When the following template is compiled and rendered in the same request, the Livewire component is assigned a corrupted
wire:keywhen smart wire keys are enabled:When the view is first rendered:
lw-2253758600-0-BLAZE_PLACEHOLDER_0_During subsequent renders:
lw-2253758600-0The problem
Livewire keeps track of last rendered
wire:keyusing a precompiler and a static cache.During compilation, it prefixes each
wire:keywith a php block that stores its value:This value is then appended to the key of the next Livewire component.
The problem is that this also happens during isolated rendering, which poisons the static cache.
Let's take the original example:
1. During folding:
<flux:select.option :value="$value">is folded with<flux:select.option value="BLAZE_PLACEHOLDER_0_">Because the
valueprop is internally used aswire:key, Livewire will store its value inSupportCompiledWireKeys::$currentLoop['key']during isolated rendering.2. After folding:
Result: The Livewire component gets wire key
lw-2253758600-0-BLAZE_PLACEHOLDER_0_3. On subsequent render:
Result: The Livewire component gets wire key
lw-2253758600-0The solution
The solution is to disable smart key compilation as well as all Livewire precompiles during folding as Livewire components shouldn't be folded. This PR also makes that explicit by aborting fold when Livewire components are detected.
Fixes #204