Skip to content

Fix aware mutating attribute bag - #201

Merged
ganyicz merged 7 commits into
mainfrom
filip/fix-aware-folding
Aug 11, 2026
Merged

Fix aware mutating attribute bag#201
ganyicz merged 7 commits into
mainfrom
filip/fix-aware-folding

Conversation

@ganyicz

@ganyicz ganyicz commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

The scenario

Blaze removes attributes defined in @aware from the attribute bag.

{{-- resources/views/components/input.blade.php --}}

@aware(['type'])

<input {{ $attributes }}>

Rendering <x-input type="number"> will produce:

  • <input type="number"> in Blade
  • <input > in Blaze

The component intentionally doesn't use @props to demonstrate the issue

The problem

When components are folded, they do not have access to the data stack which @aware uses. We compensate for that by appending parent attributes to the node during folding. For example, when folding <x-input> in the view below:

<x-wrapper type="number">
    <x-input> {{-- Uses @aware(['type']) --}}
</x-wrapper>

We take type="number" from the parent and add it to the node itself before rendering:

<x-input type="number">`

This provides the parent data to the component, however, it also adds type to the attribute bag. We then have to unset($attributes['type']) when compiling @aware, which causes the original issue.

This only affects a narrow use-case: if @props aren't used or if the attribute bag is accessed before @aware but it highlights a real divergence from Blade.

The solution

Provide parent data via data stack and stop mutating the attribute bag from inside @aware.

$awareData = Arr::map($renderable->parentAttributes, ...);
$attributes = Arr::map($renderable->attributes, ...);

$this->runtime->pushData($awareData);
$this->runtime->pushData($attributes);

require $compiled;

$this->runtime->popData();
$this->runtime->popData();

We've already had an isolated data stack, however we only pushed $attributes which only containes the data of the component that is currently rendered. Adding $awareData fixes the issue and the attribute bag can remain untouched.

This supersedes PR #200, which uncovered this issue.

@ganyicz ganyicz changed the title Fix aware folding Fix aware mutating attribute bag Aug 11, 2026
@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Benchmark Result: Default

Attempt Blade Blaze Change
#1 246.87ms 15.21ms 93.8%
#2 239.72ms 15.38ms 93.6%
#3 242.08ms 15.21ms 93.7%
#4 240.49ms 15.25ms 93.7%
#5 241.73ms 15.19ms 93.7%
#6 239.97ms 15.51ms 93.5%
#7 242.58ms 15.44ms 93.6%
#8 244.28ms 15.26ms 93.8%
#9 * 242.60ms 15.83ms 93.5%
#10 245.60ms 15.25ms 93.8%
Snapshot 247.33ms 15.24ms 93.8%
Result 242.08ms (-2.1%) 15.25ms (~) 93.7% (~)

Median of 10 attempts (* = outlier, excluded from result), 5000 iterations x 10 rounds, 33.17s total

To run a specific benchmark, comment /benchmark <name>
attributes, aware, class, default, forwarding, merge, named-slots, no-attributes, slot, compilation

@ganyicz

ganyicz commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator Author

/benchmark aware

@github-actions

Copy link
Copy Markdown
Contributor

Benchmark Result: Aware

Attempt Blade Blaze Change
#1 * 552.68ms 36.60ms 93.4%
#2 562.27ms 37.48ms 93.3%
#3 555.90ms 37.52ms 93.3%
#4 * 542.80ms 38.25ms 93%
#5 559.25ms 37.75ms 93.2%
#6 551.64ms 37.53ms 93.2%
#7 * 551.15ms 38.51ms 93%
#8 552.35ms 37.46ms 93.2%
#9 557.14ms 37.65ms 93.2%
#10 557.13ms 37.37ms 93.3%
Snapshot 552.33ms 38.92ms 93%
Result 557.13ms (~) 37.52ms (-3.6%) 93.3% (+0.3%)

Median of 10 attempts (* = outlier, excluded from result), 5000 iterations x 10 rounds, 73.43s total

To run a specific benchmark, comment /benchmark <name>
attributes, aware, class, default, forwarding, merge, named-slots, no-attributes, slot, compilation

@ganyicz
ganyicz merged commit 26c9686 into main Aug 11, 2026
4 checks passed
@ganyicz
ganyicz deleted the filip/fix-aware-folding branch August 11, 2026 18:31
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.

1 participant