Skip to content

Commit af85c5d

Browse files
committed
Fix initial root hierarchy creation
1 parent e8348b7 commit af85c5d

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
@@ -118,8 +118,8 @@ private function preRender(MountedComponent $mounted, array $context = []): PreR
118118
$component = $mounted->getComponent();
119119

120120
// add the "parent" component when rendering a nested embedded component
121-
if (isset($context[PreRenderEvent::EMBEDDED]) && true === $context[PreRenderEvent::EMBEDDED]) {
122-
$hierarchy = isset($context['this']) && $context['this'] instanceof Hierarchy ? $context['this'] : new Hierarchy($component);
121+
if (isset($context[PreRenderEvent::EMBEDDED]) && true === $context[PreRenderEvent::EMBEDDED] && isset($context['this'])) {
122+
$hierarchy = $context['this'] instanceof Hierarchy ? $context['this'] : new Hierarchy($context['this']);
123123
if (isset($context['this'])) {
124124
$hierarchy = $hierarchy->add($component);
125125
}

src/TwigComponent/tests/Integration/EmbeddedComponentTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ public function testBlockDefinitionCanAccessTheContextOfTheDestinationBlocks():
150150
);
151151
}
152152

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

0 commit comments

Comments
 (0)