@@ -2220,31 +2220,49 @@ To validate only on "change", use the ``on(change)`` modifier:
2220
2220
class="{{ _errors.has('post.content') ? 'is-invalid' : '' }}"
2221
2221
>
2222
2222
2223
- Deferring the Loading
2224
- ---------------------
2223
+ Deferring / Lazy Loading Components
2224
+ -----------------------------------
2225
2225
2226
- Certain components might be heavy to load. You can defer the loading of these components
2227
- until after the rest of the page has loaded. To do this, use the ``defer `` attribute:
2226
+ .. versionadded :: 2.13.0
2227
+
2228
+ The ability to defer loading a component was added in Live Components 2.13.
2229
+
2230
+ If a component is heavy to render, you can defer rendering it until after
2231
+ the page has loaded. To do this, add the ``defer `` option:
2228
2232
2229
2233
.. code-block :: twig
2230
2234
2231
2235
{{ component('SomeHeavyComponent', { defer: true }) }}
2232
2236
2233
- Doing so will render an empty "placeholder" tag with the live attributes. Once the ``live:connect `` event is triggered,
2234
- the component will be rendered asynchronously.
2237
+ This renders an empty ``<div> `` tag, but triggers an Ajax call to render the
2238
+ real component once the page has loaded.
2239
+
2240
+ .. note ::
2235
2241
2236
- By default the rendered tag is a ``div ``. You can change this by specifying the ``loading-tag `` attribute:
2242
+ Behind the scenes, your component *is * created & mounted during the initial
2243
+ page load, but it isn't rendered. So keep your heavy work to methods in
2244
+ your component (e.g. ``getProducts() ``) that are only called when rendering.
2245
+
2246
+ To add some loading text before the real component is loaded, use the
2247
+ ``loading-template `` option to point to a template:
2237
2248
2238
2249
.. code-block :: twig
2239
2250
2240
- {{ component('SomeHeavyComponent', { defer: true, loading-tag : 'span ' }) }}
2251
+ {{ component('SomeHeavyComponent', { defer: true, loading-template : 'spinning-wheel.html.twig ' }) }}
2241
2252
2242
- If you need to signify that the component is loading, use the ``loading-template `` attribute.
2243
- This lets you provide a Twig template that will render inside the "placeholder" tag:
2253
+ Or override the ``content `` block:
2244
2254
2245
2255
.. code-block :: twig
2246
2256
2247
- {{ component('SomeHeavyComponent', { defer: true, loading-template: 'spinning-wheel.html.twig' }) }}
2257
+ {% component SomeHeavyComponent with { defer: true }) }}
2258
+ {% block content %}Loading...{% endblock %}
2259
+ {{ end_component() }}
2260
+
2261
+ To change the initial tag from a ``div `` to something else, use the ``loading-tag `` option:
2262
+
2263
+ .. code-block :: twig
2264
+
2265
+ {{ component('SomeHeavyComponent', { defer: true, loading-tag: 'span' }) }}
2248
2266
2249
2267
Polling
2250
2268
-------
0 commit comments