[LiveComponent] Return StimulusAttributes from live_action() so it can be spread in a Twig component tag - #3533
Conversation
|
For 3.x, 2.x is not maintained anymore |
…n be spread in a Twig component tag
7ee58ef to
8315cba
Compare
|
Done, rebased onto |
📊 Packages dist files size differenceThanks for the PR! Here is the difference in size of the packages dist files between the base branch and the PR.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Will the following code continue to work identically? <tag {{ 'data-controller="foo bar" ' ~ live_action(...) }}> |
|
Yes, identically. 👍 Twig's Happy to add a test asserting the concatenation output if you'd like it locked down. 🙂 |
Today,
live_action()casts its return value to astring, which prevents it from being spread into a Twig component tag:stimulus_action()already returns aStimulusAttributesobject (which is both\Stringableand\IteratorAggregate), so the same call written against it does work. The asymmetry was pointed out by @squrious in the issue discussion.This PR aligns
live_action()withstimulus_action()by returning the sameStimulusAttributesobject directly. Existing usages remain unaffected because Twig calls__toString()automatically when rendering the value (e.g.<button {{ live_action('save') }}>), and the helper is marked@internalon the PHP side.The existing
LiveComponentRuntimeTest::testGetLiveActionis adapted to cast the value to string for the equality assertion and gains a newassertInstanceOfto lock the return type.