Skip to content

[TwigComponent] Fix ComponentAttributes rendering when using StimulusAttributes as default attributes #2757

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

Merged
merged 1 commit into from
May 20, 2025

Conversation

Kocal
Copy link
Member

@Kocal Kocal commented May 20, 2025

Q A
Bug fix? yes
New feature? no
Docs? yes
Issues Fix #2756
License MIT

We missed the case where we can inject StimulusAttributes when using attributes.defaults(), as documented in https://symfony.com/bundles/ux-twig-component/current/index.html#component-attributes

It looks like our tests weren't solid enough, since we asserted on all() instead of the rendered string.

@carsonbot carsonbot added Bug Bug Fix TwigComponent Status: Needs Review Needs to be reviewed labels May 20, 2025
Comment on lines 154 to 155
'data-foo-some-array-value' => '["a","b"]',
'data-foo-some-array-with-keys-value' => '{"key1":"value1","key2":"value2"}'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the fix:

Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
     'data-controller' => 'foo live'
     'data-live-data-value' => '{}'
     'data-foo-name-value' => 'ryan'
-    'data-foo-some-array-value' => '["a","b"]'
-    'data-foo-some-array-with-keys-value' => '{"key1":"value1","key2":"value2"}'
+    'data-foo-some-array-value' => '["a","b"]'
+    'data-foo-some-array-with-keys-value' => '{"key1":"value1","key2":"value2"}'
 )

], $attributes->all());
$this->assertSame(' data-controller="foo live" data-foo-name-value="ryan" data-foo-some-array-value="["a","b"]" data-foo-some-array-with-keys-value="{"key1":"value1","key2":"value2"}" class="foo" data-live-data-value="{}"', (string) $attributes);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the fix:

Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-' data-controller="foo live" data-foo-name-value="ryan" data-foo-some-array-value="["a","b"]" data-foo-some-array-with-keys-value="{"key1":"value1","key2":"value2"}" class="foo" data-live-data-value="{}"'
+' data-controller="foo live" data-foo-name-value="ryan" data-foo-some-array-value="["a","b"]" data-foo-some-array-with-keys-value="{"key1":"value1","key2":"value2"}" class="foo" data-live-data-value="{}"'

@Kocal Kocal force-pushed the fix-2756-twig-comp-stimulus-escape branch from ee1aac2 to 8ed98d6 Compare May 20, 2025 13:06
@Kocal Kocal requested review from kbond and smnandre May 20, 2025 13:06
@carsonbot carsonbot added Status: Reviewed Has been reviewed by a maintainer and removed Status: Needs Review Needs to be reviewed labels May 20, 2025
@Kocal Kocal merged commit 952e6e7 into symfony:2.x May 20, 2025
85 of 86 checks passed
@Kocal Kocal deleted the fix-2756-twig-comp-stimulus-escape branch May 20, 2025 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Bug Fix Status: Reviewed Has been reviewed by a maintainer TwigComponent
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Stimulus][TwigComponent] Syntax error escaping objects since 2.25.0
4 participants