Fix Flux::attributesAfter() usages
#2089
Open
+20
−9
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
Currently if you have a
label:classattribute on an input, like<flux:input label="Input 1" label:class="text-purple-500"/>, the classes are no longer forwarded since v2.6.0, where as it used to work.The problem
The issue is that in v2.6.0 we released an update to
Flux::attributesAfter()that stripped the matched values from existing$attributesto ensure they weren't also output/ doubled up where they shouldn't be.The problem with stripping comes down to how
Flux::attributesAfter()is used. One scenario works fine and the other is causing the problem described above.The working solution is when used like this:
The broken scenario is when it is used inline like this:
To understand why this is broken, we have to dive into how Blade compiles components.
When a Blade component is found, Blade compiles it down to this string:
If you look closely, you will see that
Flux::attributesAfter()is actually being called twice for the label component. This is because Blade makes use of the$attributesbag twice when rendering a component.What this means is that the first call is removing the label attributes from the
$attributebag. And the second one inside->withAttributes(), which is the one that actually passes the data to the component, can't actually find any label attributes in the$attributesbag. Hence why no attributes are being forwarded to the component.The solution
The solution is to remove the inline usages of
Flux::attributesAfter()and make use of a temporary variable, to ensure the attributes are pulled and collected only once and then that bag is included with the component.I have checked Flux Pro and all components that use
Flux::attributesAfter()are already using temporary variables, so there was only a couple of components that needed to be updated on this repo.Now it's all working as expected again.
Fixes #2056