diff --git a/src/LiveComponent/src/Metadata/LiveComponentMetadataFactory.php b/src/LiveComponent/src/Metadata/LiveComponentMetadataFactory.php index a0176ecf449..d89a253e3f8 100644 --- a/src/LiveComponent/src/Metadata/LiveComponentMetadataFactory.php +++ b/src/LiveComponent/src/Metadata/LiveComponentMetadataFactory.php @@ -25,6 +25,9 @@ */ class LiveComponentMetadataFactory { + /** @var LiveComponentMetadata[] */ + private array $liveComponentMetadata = []; + public function __construct( private ComponentFactory $componentFactory, private PropertyTypeExtractorInterface $propertyTypeExtractor, @@ -33,12 +36,16 @@ public function __construct( public function getMetadata(string $name): LiveComponentMetadata { + if (isset($this->liveComponentMetadata[$name])) { + return $this->liveComponentMetadata[$name]; + } + $componentMetadata = $this->componentFactory->metadataFor($name); $reflectionClass = new \ReflectionClass($componentMetadata->getClass()); $livePropsMetadata = $this->createPropMetadatas($reflectionClass); - return new LiveComponentMetadata($componentMetadata, $livePropsMetadata); + return $this->liveComponentMetadata[$name] = new LiveComponentMetadata($componentMetadata, $livePropsMetadata); } /**