Skip to content

Commit f34c2ba

Browse files
authored
fix(view): check the existing of the $tagName property (#803)
1 parent 9d39e15 commit f34c2ba

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/Tempest/View/src/Elements/ElementFactory.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Tempest\View\Renderers\TempestViewCompiler;
1313
use Tempest\View\ViewComponent;
1414
use Tempest\View\ViewConfig;
15+
use const XML_ELEMENT_NODE;
1516
use function Tempest\Support\str;
1617

1718
final class ElementFactory
@@ -51,7 +52,11 @@ private function makeElement(Node $node, ?Element $parent): ?Element
5152
);
5253
}
5354

54-
$tagName = $node->tagName ? strtolower($node->tagName) : null;
55+
$tagName = null;
56+
57+
if ($node->nodeType == XML_ELEMENT_NODE) {
58+
$tagName = strtolower($node->tagName);
59+
}
5560

5661
$attributes = [];
5762

tests/Integration/View/TempestViewRendererTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,4 +418,26 @@ public function test_view_component_with_multiple_attributes(): void
418418
$html = $this->render(view('<x-view-component-with-multiple-attributes :a="\'a\'" b="b"></x-view-component-with-multiple-attributes>'));
419419
$this->assertStringEqualsStringIgnoringLineEndings($expected, $html);
420420
}
421+
422+
public function test_slot_with_comment(): void
423+
{
424+
$this->assertSame(
425+
<<<'HTML'
426+
<div class="base">
427+
428+
429+
Test
430+
431+
</div>
432+
HTML,
433+
$this->render(
434+
<<<'HTML'
435+
<x-base-layout>
436+
<!-- example of comment -->
437+
Test
438+
</x-base-layout>
439+
HTML,
440+
),
441+
);
442+
}
421443
}

0 commit comments

Comments
 (0)