Skip to content

[13.x] Render bound attributes of dynamic class components like the component tag - #62455

Merged
taylorotwell merged 1 commit into
13.xfrom
13.x-dynamic-component-bound-attributes
Nov 13, 2026
Merged

taylorotwell merged 1 commit into
13.xfrom
13.x-dynamic-component-bound-attributes

Conversation

@pushpak1300

Copy link
Copy Markdown
Member

<x-dynamic-component> renders bound attributes differently from the component tag it stands in for when the target is a class component:

<x-alert :title="$title" />                                   {{-- title="&quot;Quotes&quot; &amp; &lt;tags&gt;" --}}
<x-dynamic-component component="alert" :title="$title" />      {{-- title="\"Quotes\" & <tags>" --}}

The dynamic component tag compiles its attributes without encoding them, so that anonymous targets don't encode them twice (#34346). Class targets receive those attributes through {{ $attributes }}, which doesn't encode them again, so bound values that aren't constructor parameters reach the HTML as they are.

The compiler now passes the names of the bound attributes to DynamicComponent. When the target is a class, DynamicComponent applies BladeCompiler::sanitizeComponentAttribute() to those values before they are merged into the attribute bag, which is what the component tag does. As a result:

Attribute on a class target Before After
:title="$title" not encoded encoded, same as <x-alert>
title="{{ $title }}", title="static" encoded once unchanged
Constructor parameters, HtmlString, models, collections passed as is unchanged
Forwarded {{ $attributes }} encoded once unchanged
Anonymous targets encoded once unchanged

The test renders each form through <x-dynamic-component> and through the component tag and asserts that the output is identical.

Note

Compiled views keep the previous behavior until they are recompiled with php artisan view:clear or php artisan view:cache.

@taylorotwell
taylorotwell merged commit 98d49e7 into 13.x Nov 13, 2026
65 checks passed
@taylorotwell
taylorotwell deleted the 13.x-dynamic-component-bound-attributes branch November 13, 2026 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants