-
-
Notifications
You must be signed in to change notification settings - Fork 364
[StimulusBundle] feat: normalize parameters names given to twig helper 'stimulus_action' #1193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[StimulusBundle] feat: normalize parameters names given to twig helper 'stimulus_action' #1193
Conversation
Nice catch @norival ! @weaverryan : Is it seen as a bugfix.. or a new feature ? In the later, BC break alert :) |
What would the |
Well after playing with this a bit, i'm 100% to consider this a bugfix. And it's more a "HTML/DOM/JS" problem than a specific Stimulus one. <div data-foo-bar="foo-bar" data-fooBar="fooBar">...</div>
<div data-fooBar="fooBar" data-foo-bar="foo-bar">...</div> ![]() Data attributes are case-incensitive (and parsed in lowercase), and the snake to camelCase conversion between HTML and JS is the expected behaviour. Big CrocodileGiven a parameter named BeforeBefore the fix made by @norival , the HTML code rendered by the function was <button
data-action="foo#bar"
data-foo-bigCrocodile-param="green"
>...</button> But in the Stimulus controller, the parameters passed were in lowercase {bigcrocodile: "green"} AfterAfter the fix, the HTML code will be <button
data-action="foo#bar"
data-foo-big-crocodile-param="green"
>...</button> and the parameters passed to the action {bigCrocodile: "green"} That also means that is someone called the stimulusAction with snake-case parameters, nothing changes (they still get the parameter in camelCase) |
Great analysis @smnandre ! 😃 Actually, I think there is a case where it would break things. If you declare the parameters in the twig function like this: {{ stimulus_action('controller', 'action', 'click', {bigCrocodile: "green"}) }} this will render |
I don't find where this transformation is done (bigCrocodile -> bigcrocodile in HTML) ? |
My bad, the HTML is indeed |
I checked, and Stimulus handles it (on macOs / Firefox + Chrome) as {bigcrocodile: green} indeed. So there is a difference. But... if a developer passed "bigCrocodile" in HTML and then manually used "bigcrocodile" in the JS code.... they should have made the PR you just wrote instead :)) |
Haha, I agree, that would be a bit weird 😅 |
Can you update the CHANGELOG entry to make it a little longer and explain the behavior change if you were relying on the broken behavior? |
ccb221a
to
557553b
Compare
@weaverryan done! Is it ok like that? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last tweak :)
src/StimulusBundle/CHANGELOG.md
Outdated
@@ -1,5 +1,9 @@ | |||
# CHANGELOG | |||
|
|||
## 2.13.0 | |||
|
|||
- Normalize parameters names given to twig helper 'stimulus_action()'. **BC Break**: previously, parameters given in camelCase (eg. `bigCrocodile`) would be registered by the controller as flatcase (`event.params.bigcrocodile`). Now, they are registered as camelCase (`event.params.bigCrocodile`) as expected. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Break onto multiple lines when it gets long (around 72ish chars) and indent the other lines the same as the word Normalize
. Also, slight rewording:
camelCase (eg.
bigCrocodile
) were incorrectly registered ...
And change the last sentence to:
This was fixed, which means they are now correctly registered as camelCase (
event.params.bigCrocodile
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And... long live the crocodile 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 😃
…r 'stimulus_action()' This allows giving a parameter name as 'myParam', and it will be printed as 'data-controller-name-my-param-param', which will be interpreted as 'event.param.myParam' by the Stimulus controller. **BC Break**: previously, parameters given in camelCase (eg. `bigCrocodile`) were incorrectly registered by the controller as flatcase (`event.params.bigcrocodile`). This was fixed, which means they are now correctly registered as camelCase (`event.params.bigCrocodile`).
557553b
to
ed02dad
Compare
Thank you Xavier! |
This allows giving a parameter name as 'myParam', and it will be printed as 'data-controller-name-my-param-param', which will be interpreted as 'myParam' by the Stimulus controller.