Fix aware mutating attribute bag - #201
Merged
Merged
Conversation
Contributor
Benchmark Result: Default
Median of 10 attempts (* = outlier, excluded from result), 5000 iterations x 10 rounds, 33.17s total To run a specific benchmark, comment |
Collaborator
Author
|
/benchmark aware |
Contributor
Benchmark Result: Aware
Median of 10 attempts (* = outlier, excluded from result), 5000 iterations x 10 rounds, 73.43s 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
Blaze removes attributes defined in
@awarefrom the attribute bag.Rendering
<x-input type="number">will produce:<input type="number">in Blade<input >in BlazeThe component intentionally doesn't use
@propsto demonstrate the issueThe problem
When components are folded, they do not have access to the data stack which
@awareuses. We compensate for that by appending parent attributes to the node during folding. For example, when folding<x-input>in the view below:We take
type="number"from the parent and add it to the node itself before rendering:This provides the parent data to the component, however, it also adds
typeto the attribute bag. We then have tounset($attributes['type'])when compiling@aware, which causes the original issue.This only affects a narrow use-case: if
@propsaren't used or if the attribute bag is accessed before@awarebut it highlights a real divergence from Blade.The solution
Provide parent data via data stack and stop mutating the attribute bag from inside
@aware.We've already had an isolated data stack, however we only pushed
$attributeswhich only containes the data of the component that is currently rendered. Adding$awareDatafixes the issue and the attribute bag can remain untouched.This supersedes PR #200, which uncovered this issue.