-
-
Notifications
You must be signed in to change notification settings - Fork 383
Description
Since 2.25.x using the documented way to merge a stimulus_controller with a twig component attributes results in a javascript syntax error when an object is passed as parameter.
I reproduced this on a new test project, using a simple component with a dummy object like this:
<div{{ attributes.defaults(stimulus_controller('test', { myObject: {someProperty: 'test'} })) }}>
KO: javascript error, unable to parse the myObject attribute
</div>
With the stimulus controller waiting an object for "myObject", it gives the following syntax error:
Uncaught (in promise) SyntaxError: Expected property name or '}' in JSON at position 1 (line 1 column 2)
It seems that using this syntax to merge the attributes & stimulus_controller escape the stimulus controller attributes in a "bad" way that makes the controller unable to parse it by default.
As a workaround, using toArray on the stimulus_controller result like this seems to work:
<div{{ attributes.defaults(stimulus_controller('test', { myObject: {someProperty: 'test'} }).toArray()) }}>
OK: attributes parsed
</div>