Skip to content

Preserve literal static attributes when folding#185

Merged
ganyicz merged 2 commits into
mainfrom
josh/preserve-literal-static-attributes
Jun 30, 2026
Merged

Preserve literal static attributes when folding#185
ganyicz merged 2 commits into
mainfrom
josh/preserve-literal-static-attributes

Conversation

@joshhanley

Copy link
Copy Markdown
Member

The Scenario

A user has a Flux radio group bound to a nullable boolean property using Livewire's .boolean modifier. Without Blaze, selecting the false radio option updates the property to false as expected. With Blaze enabled, selecting the false option still behaves as truthy, so the property appears to always be true.

<flux:radio.group wire:model.boolean.live="testBoolean" variant="cards">
    <flux:radio value="true" label="here is true" />
    <flux:radio value="false" label="here is false" />
</flux:radio.group>

The Problem

Blaze folding resolves static attribute values through Attribute::getStaticValue() before rendering folded output. That method was converting any static true, false, or null string into the equivalent PHP value, even when the attribute was not bound.

That meant value="false" became boolean false during folded rendering and was omitted by the attribute bag. Flux radio elements generate a fallback value when no value attribute is present, so the false option ended up with a generated non-empty string instead of "false".

Meanwhile, value="true" became boolean true and rendered as value="value". Livewire's .boolean modifier therefore received non-empty strings for both options, causing the false option to behave as truthy.

The Solution

This changes folded static attribute resolution so unbound literal values are kept as strings instead of being treated as PHP constants. Now value="false" stays "false" during folding and renders the same way it does in Blade.

Fixes livewire/flux#2651

@github-actions

github-actions Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Benchmark Result: Default

Attempt Blade Blaze Improvement
#1 351.85ms 16.18ms 95.4%
#2 357.24ms 16.07ms 95.5%
#3 350.33ms 16.29ms 95.4%
#4 353.47ms 16.05ms 95.5%
#5 358.86ms 15.92ms 95.6%
#6 351.67ms 16.38ms 95.3%
#7 354.67ms 16.12ms 95.5%
#8 345.44ms 15.96ms 95.4%
#9 353.23ms 15.98ms 95.5%
#10 349.94ms 16.01ms 95.4%
Snapshot 351.41ms 16.18ms 95.4%
Result 352.54ms (~) 16.06ms (~) 95.4% (~)

Median of 10 attempts, 5000 iterations x 10 rounds, 46.4s total

To run a specific benchmark, comment /benchmark <name> where name is one of: attributes, aware, class, default, forwarding, merge, named-slots, no-attributes, slot

@ganyicz

ganyicz commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Thanks!

I pushed a refactor to simplify the conditionals inside getStaticValue() + added a test for that method specifically.

@ganyicz ganyicz merged commit a4628d0 into main Jun 30, 2026
4 checks passed
@ganyicz ganyicz deleted the josh/preserve-literal-static-attributes branch June 30, 2026 13:22
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.

Radio card breaks with blaze active on boolean

2 participants