@@ -2350,6 +2350,8 @@ a model in a child updates, it won't also update that model in its parent
2350
2350
The parent-child system is *smart *. And with a few tricks, you can make
2351
2351
it behave exactly like you need.
2352
2352
2353
+ .. _child-component-independent-rerender :
2354
+
2353
2355
Each component re-renders independent of one another
2354
2356
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2355
2357
@@ -2631,6 +2633,8 @@ Notice that ``MarkdownTextarea`` allows a dynamic ``name``
2631
2633
attribute to be passed in. This makes that component re-usable in any
2632
2634
form.
2633
2635
2636
+ .. _rendering-loop-of-elements :
2637
+
2634
2638
Rendering Quirks with List of Elements
2635
2639
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2636
2640
@@ -2648,6 +2652,8 @@ each element
2648
2652
</div>
2649
2653
{% endfor %}
2650
2654
2655
+ .. _key-prop :
2656
+
2651
2657
Rendering Quirks with List of Embedded Components
2652
2658
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2653
2659
@@ -2678,6 +2684,8 @@ which will be used to identify each child component. You can
2678
2684
also pass in a ``data-live-id `` attribute directly, but ``key `` is
2679
2685
a bit more convenient.
2680
2686
2687
+ .. _rendering-loop-new-element :
2688
+
2681
2689
Tricks with a Loop + a "New" Item
2682
2690
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2683
2691
@@ -2831,6 +2839,40 @@ The system doesn't handle every edge case, so here are some things to keep in mi
2831
2839
that change is **lost **: the element will be re-added in its original location
2832
2840
during the next re-render.
2833
2841
2842
+ The Mystical data-live-id Attribute
2843
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2844
+
2845
+ The ``data-live-id `` attribute is mentioned several times throughout the documentation
2846
+ to solve various problems. It's usually not needed, but can be the key to solving
2847
+ certain complex problems. But what is it?
2848
+
2849
+ .. note ::
2850
+
2851
+ The :ref: `key prop <key-prop >` is used to create a ``data-live-id `` attribute
2852
+ on child components. So everything in this section applies equally to the
2853
+ ``key `` prop.
2854
+
2855
+ The ``data-live-id `` attribute is a unique identifier for an element or a component.
2856
+ It's used when a component re-renders and helps Live Components "connect" elements
2857
+ or components in the existing HTML with the new HTML. The logic works like this:
2858
+
2859
+ Suppose an element or component in the new HTML has a ``data-live-id="some-id `` attribute.
2860
+ Then:
2861
+
2862
+ A) If there **is ** an element or component with ``data-live-id="some-id" `` in the
2863
+ existing HTML, then the old and new elements/components are considered to be the
2864
+ "same". For elements, the new element will be used to update the old element even
2865
+ if the two elements appear in different places - e.g. like if :ref: `elements are moved <rendering-loop-of-elements >`
2866
+ or re-ordered. For components, because child components render independently
2867
+ from their parent, the existing component will be "left alone" and not re-rendered
2868
+ (unless some ``updateFromParent `` props have changed - see :ref: `child-component-independent-rerender `).
2869
+
2870
+ B) If there is **not ** an element or component with ``data-live-id="some-id" `` in
2871
+ the existing HTML, then the new element or component is considered to be "new".
2872
+ In both cases, the new element or component will be added to the page. If there
2873
+ is a component/element with a ``data-live-id `` attribute that is *not * in the
2874
+ new HTML, that component/element will be removed from the page.
2875
+
2834
2876
Skipping Updating Certain Elements
2835
2877
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2836
2878
0 commit comments