Skip to content

Commit 96595c3

Browse files
committed
Fix initial root hierarchy creation
1 parent 723ddfd commit 96595c3

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/TwigComponent/src/ComponentRenderer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ private function preRender(MountedComponent $mounted, array $context = []): PreR
9191
$component = $mounted->getComponent();
9292

9393
// add the "parent" component when rendering a nested embedded component
94-
if (isset($context[PreRenderEvent::EMBEDDED]) && true === $context[PreRenderEvent::EMBEDDED]) {
95-
$hierarchy = isset($context['this']) && $context['this'] instanceof Hierarchy ? $context['this'] : new Hierarchy($component);
94+
if (isset($context[PreRenderEvent::EMBEDDED]) && true === $context[PreRenderEvent::EMBEDDED] && isset($context['this'])) {
95+
$hierarchy = $context['this'] instanceof Hierarchy ? $context['this'] : new Hierarchy($context['this']);
9696
if (isset($context['this'])) {
9797
$hierarchy = $hierarchy->add($component);
9898
}

src/TwigComponent/tests/Integration/EmbeddedComponentTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ public function testBlockDefinitionCanAccessTheContextOfTheDestinationBlocks():
140140
);
141141
}
142142

143-
public function testAccessingTheHierarchyToHighThrowsAnException(): void
143+
public function testAccessingTheHierarchyTooHighThrowsAnException(): void
144144
{
145-
$this->expectExceptionMessage('Impossible to access an attribute ("foo") on a null variable');
145+
$this->expectExceptionMessage('Neither the property "parent" nor one of the methods "parent()", "getparent()"/"isparent()"/"hasparent()" or "__call()" exist');
146146
self::getContainer()->get(Environment::class)->render('embedded_component_hierarchy_exception.html.twig');
147147
}
148148

0 commit comments

Comments
 (0)