Skip to content

Commit eebd1c9

Browse files
TheDutchScorpionweaverryan
authored andcommitted
Fix instantiating LiveComponentMetadata multiple times
1 parent cb14051 commit eebd1c9

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Metadata/LiveComponentMetadataFactory.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
*/
2626
class LiveComponentMetadataFactory
2727
{
28+
/** @var LiveComponentMetadata[] */
29+
private array $liveComponentMetadata = [];
30+
2831
public function __construct(
2932
private ComponentFactory $componentFactory,
3033
private PropertyTypeExtractorInterface $propertyTypeExtractor,
@@ -33,12 +36,16 @@ public function __construct(
3336

3437
public function getMetadata(string $name): LiveComponentMetadata
3538
{
39+
if (isset($this->liveComponentMetadata[$name])) {
40+
return $this->liveComponentMetadata[$name];
41+
}
42+
3643
$componentMetadata = $this->componentFactory->metadataFor($name);
3744

3845
$reflectionClass = new \ReflectionClass($componentMetadata->getClass());
3946
$livePropsMetadata = $this->createPropMetadatas($reflectionClass);
4047

41-
return new LiveComponentMetadata($componentMetadata, $livePropsMetadata);
48+
return $this->liveComponentMetadata[$name] = new LiveComponentMetadata($componentMetadata, $livePropsMetadata);
4249
}
4350

4451
/**

0 commit comments

Comments
 (0)