Skip to content

Commit f32584d

Browse files
committed
Fix initial root hierarchy creation
1 parent c499aaa commit f32584d

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

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

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)