Skip to content

Commit 6f2fa9c

Browse files
committed
minor symfony#2699 key is more reliable with child components (weaverryan)
This PR was merged into the 2.x branch. Discussion ---------- key is more reliable with child components | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Docs? | yes | Issues | Fix symfony#1643 | License | MIT I couldn't track down why, but for child components, `key` is more reliable. When `id` is used and a child requires re-rendering (because input props changed), the dummy element returned by https://github.com/symfony/ux/blob/2.x/src/LiveComponent/src/EventListener/InterceptChildComponentRenderSubscriber.php will not have an `id`, but with `key` it will. Smells like a bug, but `key` works Commits ------- 304acf8 key is more reliable with child components
2 parents 5a5dcd6 + 304acf8 commit 6f2fa9c

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

src/LiveComponent/doc/index.rst

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3202,14 +3202,14 @@ Rendering Quirks with List of Elements
32023202

32033203
If you're rendering a list of elements in your component, to help LiveComponents
32043204
understand which element is which between re-renders (i.e. if something re-orders
3205-
or removes some of those elements), you can add a ``id`` attribute to
3205+
or removes some of those elements), you can add a ``key`` attribute to
32063206
each element
32073207

32083208
.. code-block:: html+twig
32093209

32103210
{# templates/components/Invoice.html.twig #}
32113211
{% for lineItem in lineItems %}
3212-
<div id="{{ lineItem.id }}">
3212+
<div key="{{ lineItem.id }}">
32133213
{{ lineItem.name }}
32143214
</div>
32153215
{% endfor %}
@@ -3224,10 +3224,6 @@ the list changes as the user types into a search box... or by clicking
32243224
"delete" on an item. In this case, the wrong children may be removed
32253225
or existing child components may not disappear when they should.
32263226

3227-
.. versionadded:: 2.8
3228-
3229-
The ``key`` prop was added in Symfony UX Live Component 2.8.
3230-
32313227
To fix this, add a ``key`` prop to each child component that's unique
32323228
to that component:
32333229

@@ -3242,9 +3238,7 @@ to that component:
32423238
{% endfor %}
32433239
32443240
The ``key`` will be used to generate an ``id`` attribute,
3245-
which will be used to identify each child component. You can
3246-
also pass in a ``id`` attribute directly, but ``key`` is
3247-
a bit more convenient.
3241+
which will be used to identify each child component.
32483242

32493243
.. _rendering-loop-new-element:
32503244

0 commit comments

Comments
 (0)