-
-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #1097 [LiveComponent] Only consider Live components in InterceptC…
…hildComponentRenderSubscriber (sneakyvv) This PR was merged into the 2.x branch. Discussion ---------- [LiveComponent] Only consider Live components in InterceptChildComponentRenderSubscriber | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | Tickets | | License | MIT This PR is related to the change of #1093. ### Problem The component stack now also contains embedded Components until they are fully rendered, which is good. But, that also means that with this setup ``` {# someTemplate #} <twig:aLiveComponent> <twig:aTwigComponent> <twig:anotherLiveComponent> {# ... #} </twig:anotherLiveComponent> </twig:aTwigComponent> </twig:aLiveComponent> ``` when re-rendering the `anotherLiveComponent` the `InterceptChildComponentRenderSubscriber` would look at the parent component's `childrenFingerprints` to determine if it can short-circuit the rendering process for `anotherLiveComponent` and return an empty html element causing the FE to not do a callback to re-render it. However since that parent is a non-live component it will never short-circuit. ### Solution Only take live components into account. Commits ------- 953721e [LiveComponent] Only consider Live components in InterceptChildComponentRenderSubscriber
- Loading branch information
Showing
4 changed files
with
69 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Symfony\UX\LiveComponent\Util; | ||
|
||
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent; | ||
use Symfony\UX\TwigComponent\ComponentStack; | ||
use Symfony\UX\TwigComponent\MountedComponent; | ||
|
||
/** | ||
* This class decorates the TwigComponent\ComponentStack adding specific Live component functionalities. | ||
* | ||
* @author Bart Vanderstukken <bart.vanderstukken@gmail.com> | ||
* | ||
* @internal | ||
*/ | ||
final class LiveComponentStack extends ComponentStack | ||
{ | ||
public function __construct(private readonly ComponentStack $componentStack) | ||
{ | ||
} | ||
|
||
public function getCurrentLiveComponent(): ?MountedComponent | ||
{ | ||
foreach ($this->componentStack as $mountedComponent) { | ||
if ($this->isLiveComponent($mountedComponent->getComponent()::class)) { | ||
return $mountedComponent; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
private function isLiveComponent(string $classname): bool | ||
{ | ||
return [] !== (new \ReflectionClass($classname))->getAttributes(AsLiveComponent::class); | ||
} | ||
|
||
public function getCurrentComponent(): ?MountedComponent | ||
{ | ||
return $this->componentStack->getCurrentComponent(); | ||
} | ||
|
||
public function getParentComponent(): ?MountedComponent | ||
{ | ||
return $this->componentStack->getParentComponent(); | ||
} | ||
|
||
public function hasParentComponent(): bool | ||
{ | ||
return $this->componentStack->hasParentComponent(); | ||
} | ||
} |