Skip to content

Commit 373deed

Browse files
committed
feature #1251 Fix instantiating LiveComponentMetadata multiple times (TheDutchScorpion)
This PR was squashed before being merged into the 2.x branch. Discussion ---------- Fix instantiating LiveComponentMetadata multiple times | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | Issues | N/A | License | MIT This pull request fixes an issue with instantiating LiveComponentMetadata multiple times, when loading the same component multiple times. Commits ------- 7e03119df8 Fix instantiating LiveComponentMetadata multiple times
2 parents 0131de0 + eebd1c9 commit 373deed

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)