Skip to content

Preserve literal static attributes when folding#185

Open
joshhanley wants to merge 1 commit into
mainfrom
josh/preserve-literal-static-attributes
Open

Preserve literal static attributes when folding#185
joshhanley wants to merge 1 commit 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

Copy link
Copy Markdown
Contributor

Benchmark Result: Default

Attempt Blade Blaze Improvement
#1 338.90ms 15.66ms 95.4%
#2 352.78ms 15.84ms 95.5%
#3 349.62ms 15.70ms 95.5%
#4 348.13ms 15.96ms 95.4%
#5 338.83ms 15.67ms 95.4%
#6 343.66ms 15.49ms 95.5%
#7 346.79ms 16.01ms 95.4%
#8 344.46ms 15.82ms 95.4%
#9 350.18ms 15.78ms 95.5%
#10 345.21ms 15.64ms 95.5%
Snapshot 345.69ms 15.72ms 95.5%
Result 346.00ms (~) 15.74ms (~) 95.5% (~)

Median of 10 attempts, 5000 iterations x 10 rounds, 45.56s 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

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

1 participant