Skip to content

Commit 31f4a0a

Browse files
committed
Set the template to deferred if the component is deferred and rendered for the first time
1 parent 7e6c111 commit 31f4a0a

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/LiveComponent/src/EventListener/AddLiveAttributesSubscriber.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ public function onPreRender(PreRenderEvent $event): void
7373
$originalAttributes['data-embedded-template-index'],
7474
);
7575
}
76+
77+
$hasLiveId = isset($originalAttributes['data-live-id']);
78+
$isDeferred = array_key_exists('defer', $originalAttributes);
79+
80+
// if the original attributes has a data-live-id, it means the component
81+
// was already rendered
82+
if (!$hasLiveId && $isDeferred) {
83+
$attributes = $attributes->without('defer');
84+
$event->setTemplate('@LiveComponent/deferred.html.twig');
85+
}
7686
}
7787

7888
// "key" is a special attribute: don't actually render it
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div {{ attributes }} data-action="live:connect->live#$render"></div>

0 commit comments

Comments
 (0)