[13.x] Render bound attributes of dynamic class components like the component tag
<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=""Quotes" & <tags>" --}}
<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.