Skip to content

Commit 1bb82f2

Browse files
committed
Allow to define a loading template for deferred live component
1 parent a1c0da3 commit 1bb82f2

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/LiveComponent/src/EventListener/AddLiveAttributesSubscriber.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,17 @@ public function onPreRender(PreRenderEvent $event): void
7676

7777
$hasLiveId = isset($originalAttributes['data-live-id']);
7878
$isDeferred = array_key_exists('defer', $originalAttributes);
79+
$loadingTemplate = $originalAttributes['defer-loading-template'] ?? null;
7980

8081
// if the original attributes has a data-live-id, it means the component
8182
// was already rendered
8283
if (!$hasLiveId && $isDeferred) {
83-
$attributes = $attributes->without('defer');
84+
$attributes = $attributes->without('defer', 'defer-loading-template');
8485
$event->setTemplate('@LiveComponent/deferred.html.twig');
86+
87+
if ($loadingTemplate) {
88+
$variables['loadingTemplate'] = $loadingTemplate;
89+
}
8590
}
8691
}
8792

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
<div {{ attributes }} data-action="live:connect->live#$render"></div>
1+
<div {{ attributes }} data-action="live:connect->live#$render">
2+
{% if loadingTemplate is defined and loadingTemplate != null %}
3+
{{ include(loadingTemplate) }}
4+
{% endif %}
5+
</div>

0 commit comments

Comments
 (0)